Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AO3-6328 Try to fix large tags not updating in uses sort #4637

Merged
merged 5 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,9 @@ def after_update
end
end

# Ensure tags with count cache can be reindexed.
Rails.cache.delete(taggings_count_cache_key) if tag.saved_change_to_taggings_count_cache?

# Reindex immediately to update the unwrangled bin.
if tag.saved_change_to_unwrangleable?
tag.reindex_document
Expand Down
27 changes: 15 additions & 12 deletions spec/models/tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@
let(:tag) { create(:fandom) }
let!(:work) { create(:work, fandom_string: tag.name) }

before do
before { run_update_tag_count_job }

def run_update_tag_count_job
RedisJobSpawner.perform_now("TagCountUpdateJob")
tag.reload
end
Expand All @@ -105,8 +107,7 @@ def expect_tag_update_flag_in_redis_to_be(flag)
tag.taggings_count = 2
expect_tag_update_flag_in_redis_to_be(true)

RedisJobSpawner.perform_now("TagCountUpdateJob")
tag.reload
run_update_tag_count_job

# Actual number of taggings has not changed though count cache has.
expect(tag.taggings_count_cache).to eq 2
Expand All @@ -117,8 +118,7 @@ def expect_tag_update_flag_in_redis_to_be(flag)
create(:work, fandom_string: tag.name)
expect_tag_update_flag_in_redis_to_be(true)

RedisJobSpawner.perform_now("TagCountUpdateJob")
tag.reload
run_update_tag_count_job

expect(tag.taggings_count_cache).to eq 2
expect(tag.taggings_count).to eq 2
Expand All @@ -130,25 +130,28 @@ def expect_tag_update_flag_in_redis_to_be(flag)
REDIS_GENERAL.set("tag_update_#{tag.id}_value", "")
REDIS_GENERAL.sadd("tag_update", tag.id)

RedisJobSpawner.perform_now("TagCountUpdateJob")
run_update_tag_count_job

expect(tag.reload.taggings_count_cache).to eq 1
expect(tag.taggings_count_cache).to eq 1
end

it "triggers reindexing of tags which aren't used much" do
create(:work, fandom_string: tag.name)

expect { RedisJobSpawner.perform_now("TagCountUpdateJob") }
.to add_to_reindex_queue(tag.reload, :main)
expect { run_update_tag_count_job }
.to add_to_reindex_queue(tag, :main)
end

it "triggers reindexing of tags which are used significantly" do
ArchiveConfig.TAGGINGS_COUNT_MIN_CACHE_COUNT.times do
create(:work, fandom_string: tag.name)
end

expect { RedisJobSpawner.perform_now("TagCountUpdateJob") }
.to add_to_reindex_queue(tag.reload, :main)
expect { run_update_tag_count_job }
.to add_to_reindex_queue(tag, :main)
expect_tag_update_flag_in_redis_to_be(false)

create(:work, fandom_string: tag.name)
expect_tag_update_flag_in_redis_to_be(true)
end
end
end
Expand Down
Loading