Try having sync_reactions_count as a background job (#18991)
* Try having sync_reactable as a background job * Update test * Fix flakey test (order should not matter)
This commit is contained in:
parent
bbb8985a51
commit
909fd7f103
2 changed files with 7 additions and 11 deletions
|
|
@ -49,7 +49,7 @@ class Reaction < ApplicationRecord
|
|||
before_save :assign_points
|
||||
after_create :notify_slack_channel_about_vomit_reaction, if: -> { category == "vomit" }
|
||||
before_destroy :bust_reactable_cache_without_delay
|
||||
before_destroy :update_reactable_without_delay, unless: :destroyed_by_association
|
||||
before_destroy :update_reactable, unless: :destroyed_by_association
|
||||
after_commit :async_bust
|
||||
after_commit :bust_reactable_cache, :update_reactable, on: %i[create update]
|
||||
after_commit :record_field_test_event, on: %i[create]
|
||||
|
|
@ -194,10 +194,6 @@ class Reaction < ApplicationRecord
|
|||
Reactions::BustReactableCacheWorker.new.perform(id)
|
||||
end
|
||||
|
||||
def update_reactable_without_delay
|
||||
Reactions::UpdateRelevantScoresWorker.new.perform(id)
|
||||
end
|
||||
|
||||
def reading_time
|
||||
reactable.reading_time if category == "readinglist"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -139,10 +139,10 @@ RSpec.describe Reaction do
|
|||
|
||||
expected_result = [
|
||||
{ category: "like", count: 1 },
|
||||
{ category: "unicorn", count: 1 },
|
||||
{ category: "readinglist", count: 0 },
|
||||
{ category: "unicorn", count: 1 },
|
||||
]
|
||||
expect(described_class.count_for_article(article.id)).to eq(expected_result)
|
||||
expect(described_class.count_for_article(article.id)).to contain_exactly(*expected_result)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -234,7 +234,7 @@ RSpec.describe Reaction do
|
|||
end
|
||||
|
||||
context "when callbacks are called before destroy" do
|
||||
let(:reaction) { create(:reaction, reactable: article, user: user) }
|
||||
let!(:reaction) { create(:reaction, reactable: article, user: user) }
|
||||
|
||||
it "enqueues a ScoreCalcWorker on article reaction destroy" do
|
||||
sidekiq_assert_enqueued_with(job: Articles::ScoreCalcWorker, args: [article.id]) do
|
||||
|
|
@ -242,10 +242,10 @@ RSpec.describe Reaction do
|
|||
end
|
||||
end
|
||||
|
||||
it "updates reactable without delay" do
|
||||
allow(reaction).to receive(:update_reactable_without_delay)
|
||||
it "updates reactable with delay" do
|
||||
allow(Reactions::UpdateRelevantScoresWorker).to receive(:perform_async)
|
||||
reaction.destroy
|
||||
expect(reaction).to have_received(:update_reactable_without_delay)
|
||||
expect(Reactions::UpdateRelevantScoresWorker).to have_received(:perform_async)
|
||||
end
|
||||
|
||||
it "busts reactable cache without delay" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue