Bläddra i källkod

Fix records not being indexed sometimes (#12024)

It's possible that after commit callbacks were not firing when
exceptions occurred in the process. Also, the default Sidekiq
strategy does not push indexing jobs immediately, which is not
necessary and could be part of the issue too.
master^2
Eugen Rochko 4 år sedan
committed by GitHub
förälder
incheckning
5c42f47617
Ingen känd nyckel hittad för denna signaturen i databasen GPG-nyckel ID: 4AEE18F83AFDEB23
10 ändrade filer med 46 tillägg och 8 borttagningar
  1. +1
    -1
      app/models/account.rb
  2. +1
    -1
      app/models/account_stat.rb
  3. +6
    -0
      app/models/application_record.rb
  4. +1
    -1
      app/models/favourite.rb
  5. +1
    -1
      app/models/status.rb
  6. +1
    -1
      app/models/tag.rb
  7. +1
    -0
      config/application.rb
  8. +3
    -2
      config/initializers/chewy.rb
  9. +30
    -0
      lib/chewy/strategy/custom_sidekiq.rb
  10. +1
    -1
      spec/rails_helper.rb

+ 1
- 1
app/models/account.rb Visa fil

@@ -129,7 +129,7 @@ class Account < ApplicationRecord

delegate :chosen_languages, to: :user, prefix: false, allow_nil: true

update_index('accounts#account', :self) if Chewy.enabled?
update_index('accounts#account', :self)

def local?
domain.nil?


+ 1
- 1
app/models/account_stat.rb Visa fil

@@ -16,7 +16,7 @@
class AccountStat < ApplicationRecord
belongs_to :account, inverse_of: :account_stat

update_index('accounts#account', :account) if Chewy.enabled?
update_index('accounts#account', :account)

def increment_count!(key)
update(attributes_for_increment(key))


+ 6
- 0
app/models/application_record.rb Visa fil

@@ -5,6 +5,12 @@ class ApplicationRecord < ActiveRecord::Base

include Remotable

class << self
def update_index(_type_name, *_args, &_block)
super if Chewy.enabled?
end
end

def boolean_with_default(key, default_value)
value = attributes[key]



+ 1
- 1
app/models/favourite.rb Visa fil

@@ -13,7 +13,7 @@
class Favourite < ApplicationRecord
include Paginable

update_index('statuses#status', :status) if Chewy.enabled?
update_index('statuses#status', :status)

belongs_to :account, inverse_of: :favourites
belongs_to :status, inverse_of: :favourites


+ 1
- 1
app/models/status.rb Visa fil

@@ -39,7 +39,7 @@ class Status < ApplicationRecord
# will be based on current time instead of `created_at`
attr_accessor :override_timestamps

update_index('statuses#status', :proper) if Chewy.enabled?
update_index('statuses#status', :proper)

enum visibility: [:public, :unlisted, :private, :direct, :limited], _suffix: :visibility



+ 1
- 1
app/models/tag.rb Visa fil

@@ -49,7 +49,7 @@ class Tag < ApplicationRecord

after_save :save_account_tag_stat

update_index('tags#tag', :self) if Chewy.enabled?
update_index('tags#tag', :self)

def account_tag_stat
super || build_account_tag_stat


+ 1
- 0
config/application.rb Visa fil

@@ -15,6 +15,7 @@ require_relative '../lib/mastodon/snowflake'
require_relative '../lib/mastodon/version'
require_relative '../lib/devise/two_factor_ldap_authenticatable'
require_relative '../lib/devise/two_factor_pam_authenticatable'
require_relative '../lib/chewy/strategy/custom_sidekiq'

Dotenv::Railtie.load



+ 3
- 2
config/initializers/chewy.rb Visa fil

@@ -12,8 +12,9 @@ Chewy.settings = {
sidekiq: { queue: 'pull' },
}

Chewy.root_strategy = enabled ? :sidekiq : :bypass
Chewy.request_strategy = enabled ? :sidekiq : :bypass
Chewy.root_strategy = :custom_sidekiq
Chewy.request_strategy = :custom_sidekiq
Chewy.use_after_commit_callbacks = false

module Chewy
class << self


+ 30
- 0
lib/chewy/strategy/custom_sidekiq.rb Visa fil

@@ -0,0 +1,30 @@
# frozen_string_literal: true

module Chewy
class Strategy
class CustomSidekiq < Base
class Worker
include ::Sidekiq::Worker

sidekiq_options queue: 'pull'

def perform(type, ids, options = {})
options[:refresh] = !Chewy.disable_refresh_async if Chewy.disable_refresh_async
type.constantize.import!(ids, options)
end
end

def update(type, objects, _options = {})
return unless Chewy.enabled?

ids = type.root.id ? Array.wrap(objects) : type.adapter.identify(objects)

return if ids.empty?

Worker.perform_async(type.name, ids)
end

def leave; end
end
end
end

+ 1
- 1
spec/rails_helper.rb Visa fil

@@ -12,7 +12,7 @@ require 'capybara/rspec'
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }

ActiveRecord::Migration.maintain_test_schema!
WebMock.disable_net_connect!
WebMock.disable_net_connect!(allow: Chewy.settings[:host])
Redis.current = Redis::Namespace.new("mastodon_test#{ENV['TEST_ENV_NUMBER']}", redis: Redis.current)
Sidekiq::Testing.inline!
Sidekiq::Logging.logger = nil


Laddar…
Avbryt
Spara