You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
633 B

  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