mastodon.rb 633 B

123456789101112131415161718192021222324252627
  1. # frozen_string_literal: true
  2. module Chewy
  3. class Strategy
  4. class Mastodon < Base
  5. def initialize
  6. super
  7. @stash = Hash.new { |hash, key| hash[key] = [] }
  8. end
  9. def update(type, objects, _options = {})
  10. @stash[type].concat(type.root.id ? Array.wrap(objects) : type.adapter.identify(objects)) if Chewy.enabled?
  11. end
  12. def leave
  13. RedisConfiguration.with do |redis|
  14. redis.pipelined do |pipeline|
  15. @stash.each do |type, ids|
  16. pipeline.sadd("chewy:queue:#{type.name}", ids)
  17. end
  18. end
  19. end
  20. end
  21. end
  22. end
  23. end