forked from berserker/microblog
Change search indexing to use batches to minimize resource usage (#18451)
parent
ded5a0254a
commit
679b7158e3
10 changed files with 64 additions and 19 deletions
@ -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 |
@ -1,11 +0,0 @@ |
|||||||
# frozen_string_literal: true |
|
||||||
|
|
||||||
module Chewy |
|
||||||
class Strategy |
|
||||||
class CustomSidekiq < Sidekiq |
|
||||||
def update(_type, _objects, _options = {}) |
|
||||||
super if Chewy.enabled? |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -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 |
Loading…
Reference in new issue