diff --git a/n/nextcloud-server/nextcloud-news-updater.rb b/n/nextcloud-server/nextcloud-news-updater.rb old mode 100644 new mode 100755 index 4084960a..cbc68c28 --- a/n/nextcloud-server/nextcloud-news-updater.rb +++ b/n/nextcloud-server/nextcloud-news-updater.rb @@ -2,7 +2,8 @@ require "json" require "thwait" -NC_ROOT="/srv/www/vhosts/nextcloud-server/htdocs" +NC_ROOT = "/srv/www/vhosts/nextcloud-server/htdocs".freeze +NB_THREADS = 2 def occ( command ) `php -f #{NC_ROOT}/occ #{command}` @@ -10,11 +11,16 @@ end occ( 'news:updater:before-update' ) -ThreadsWait.all_waits( JSON.parse( occ( 'news:updater:all-feeds' ) )["feeds"] - .map do |feed| - Thread.new do - occ( "news:updater:update-feed #{feed['id']} #{feed['userId']}" ) - end -end ) +feeds = JSON.parse( occ( 'news:updater:all-feeds' ) )["feeds"] + +slices_size = (feeds.length / NB_THREADS).floor + +ThreadsWait.all_waits( feeds.each_slice( slices_size ).to_a.map do |subfeeds| + Thread.new do + subfeeds.each do |feed| + occ( "news:updater:update-feed #{feed['id']} #{feed['userId']}" ) + end + end + end ) occ( 'news:updater:after-update' )