about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2022-05-18 23:29:14 +0200
committerGitHub <noreply@github.com>2022-05-18 23:29:14 +0200
commit679b7158e3cd3881e8cbaf2d2c0c97725b3b5fd9 (patch)
tree9cc1dd73c3cd894207bf3c806234c8c919459985 /app
parentded5a0254a4d29a7384ef766a1e92467fe4ebd2b (diff)
Change search indexing to use batches to minimize resource usage (#18451)
Diffstat (limited to 'app')
-rw-r--r--app/chewy/accounts_index.rb2
-rw-r--r--app/chewy/statuses_index.rb2
-rw-r--r--app/chewy/tags_index.rb2
-rw-r--r--app/workers/scheduler/indexing_scheduler.rb26
4 files changed, 29 insertions, 3 deletions
diff --git a/app/chewy/accounts_index.rb b/app/chewy/accounts_index.rb
index 6f9ea76e9..763958a3f 100644
--- a/app/chewy/accounts_index.rb
+++ b/app/chewy/accounts_index.rb
@@ -1,7 +1,7 @@
 # frozen_string_literal: true
 
 class AccountsIndex < Chewy::Index
-  settings index: { refresh_interval: '5m' }, analysis: {
+  settings index: { refresh_interval: '30s' }, analysis: {
     analyzer: {
       content: {
         tokenizer: 'whitespace',
diff --git a/app/chewy/statuses_index.rb b/app/chewy/statuses_index.rb
index 1304aeedb..c20009879 100644
--- a/app/chewy/statuses_index.rb
+++ b/app/chewy/statuses_index.rb
@@ -3,7 +3,7 @@
 class StatusesIndex < Chewy::Index
   include FormattingHelper
 
-  settings index: { refresh_interval: '15m' }, analysis: {
+  settings index: { refresh_interval: '30s' }, analysis: {
     filter: {
       english_stop: {
         type: 'stop',
diff --git a/app/chewy/tags_index.rb b/app/chewy/tags_index.rb
index f9db2b03a..a5b139bca 100644
--- a/app/chewy/tags_index.rb
+++ b/app/chewy/tags_index.rb
@@ -1,7 +1,7 @@
 # frozen_string_literal: true
 
 class TagsIndex < Chewy::Index
-  settings index: { refresh_interval: '15m' }, analysis: {
+  settings index: { refresh_interval: '30s' }, analysis: {
     analyzer: {
       content: {
         tokenizer: 'keyword',
diff --git a/app/workers/scheduler/indexing_scheduler.rb b/app/workers/scheduler/indexing_scheduler.rb
new file mode 100644
index 000000000..3a6f47a29
--- /dev/null
+++ b/app/workers/scheduler/indexing_scheduler.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class Scheduler::IndexingScheduler
+  include Sidekiq::Worker
+  include Redisable
+
+  sidekiq_options retry: 0
+
+  def perform
+    indexes.each do |type|
+      with_redis do |redis|
+        ids = redis.smembers("chewy:queue:#{type.name}")
+
+        type.import!(ids)
+
+        redis.pipelined do |pipeline|
+          ids.each { |id| pipeline.srem("chewy:queue:#{type.name}", id) }
+        end
+      end
+    end
+  end
+
+  def indexes
+    [AccountsIndex, TagsIndex, StatusesIndex]
+  end
+end