about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorTakeshi Umeda <noel.yoshiba@gmail.com>2019-10-03 04:50:43 +0900
committerEugen Rochko <eugen@zeonfederated.com>2019-10-02 21:50:43 +0200
commit0ce0baa9b5799be61fed7fc509837ca0ba971402 (patch)
treecef6bcf423aab912e2fb10be2b08b0e8e4e78ba9 /lib
parent4e1afef6f9eb29714c72e2c67b16569e22558f66 (diff)
Add parallelization to `tootctl search deploy` (#12051)
* Add parallel gem

* Modify parallel option in tootctl search deploy

* Add paralell option to tootctl search deploy

* Change 1 to false

* Clean up

* Rename --parallel to --processes
Diffstat (limited to 'lib')
-rw-r--r--lib/mastodon/search_cli.rb23
1 files changed, 21 insertions, 2 deletions
diff --git a/lib/mastodon/search_cli.rb b/lib/mastodon/search_cli.rb
index 42ad93f1e..8bd5f9543 100644
--- a/lib/mastodon/search_cli.rb
+++ b/lib/mastodon/search_cli.rb
@@ -6,6 +6,7 @@ require_relative 'cli_helper'
 
 module Mastodon
   class SearchCLI < Thor
+    option :processes, default: 2, aliases: [:p]
     desc 'deploy', 'Create or update an ElasticSearch index and populate it'
     long_desc <<~LONG_DESC
       If ElasticSearch is empty, this command will create the necessary indices
@@ -13,10 +14,28 @@ module Mastodon
 
       This command will also upgrade indices if the underlying schema has been
       changed since the last run.
+
+      With the --processes option, parallelize execution of the command. The
+      default is 2. If "auto" is specified, the number is automatically
+      derived from available CPUs.
     LONG_DESC
     def deploy
-      processed = Chewy::RakeHelper.upgrade
-      Chewy::RakeHelper.sync(except: processed)
+      processed = Chewy::RakeHelper.upgrade(parallel: processes)
+      Chewy::RakeHelper.sync(except: processed, parallel: processes)
+    end
+
+    private
+
+    def processes
+      return true if options[:processes] == 'auto'
+
+      num = options[:processes].to_i
+
+      if num < 2
+        nil
+      else
+        num
+      end
     end
   end
 end