about summary refs log tree commit diff
path: root/lib/chewy/strategy/mastodon.rb
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 /lib/chewy/strategy/mastodon.rb
parentded5a0254a4d29a7384ef766a1e92467fe4ebd2b (diff)
Change search indexing to use batches to minimize resource usage (#18451)
Diffstat (limited to 'lib/chewy/strategy/mastodon.rb')
-rw-r--r--lib/chewy/strategy/mastodon.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/chewy/strategy/mastodon.rb b/lib/chewy/strategy/mastodon.rb
new file mode 100644
index 000000000..ee8b92186
--- /dev/null
+++ b/lib/chewy/strategy/mastodon.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+module Chewy
+  class Strategy
+    class Mastodon < Base
+      def initialize
+        super
+
+        @stash = Hash.new { |hash, key| hash[key] = [] }
+      end
+
+      def update(type, objects, _options = {})
+        @stash[type].concat(type.root.id ? Array.wrap(objects) : type.adapter.identify(objects)) if Chewy.enabled?
+      end
+
+      def leave
+        RedisConfiguration.with do |redis|
+          redis.pipelined do |pipeline|
+            @stash.each do |type, ids|
+              pipeline.sadd("chewy:queue:#{type.name}", ids)
+            end
+          end
+        end
+      end
+    end
+  end
+end