Skip to content

Commit

Permalink
AO3-6328 Fix outdated code and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
weeklies committed Sep 16, 2023
1 parent 018d38a commit 7c55cd8
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 28 deletions.
2 changes: 1 addition & 1 deletion app/jobs/tag_count_update_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def perform_on_batch(tag_ids)
Tag.transaction do
tag_ids.each do |id|
value = REDIS_GENERAL.get("tag_update_#{id}_value")
Tag.where(id: id).update_all(taggings_count_cache: value) if value.present?
Tag.where(id: id).update(taggings_count_cache: value) if value.present?
end
end
end
Expand Down
15 changes: 0 additions & 15 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,6 @@ def document_json
TagIndexer.new({}).document(self)
end

def self.write_redis_to_database
batch_size = ArchiveConfig.TAG_UPDATE_BATCH_SIZE
REDIS_GENERAL.smembers("tag_update").each_slice(batch_size) do |batch|
Tag.transaction do
batch.each do |id|
value = REDIS_GENERAL.get("tag_update_#{id}_value")
next if value.blank?

Tag.where(id: id).update(taggings_count_cache: value.to_i)
end
REDIS_GENERAL.srem("tag_update", batch)
end
end
end

def self.taggings_count_expiry(count)
# What we are trying to do here is work out a resonable amount of time for a work to be cached for
# This should take the number of taggings and divide it by TAGGINGS_COUNT_CACHE_DIVISOR ( defaults to 1500 )
Expand Down
8 changes: 4 additions & 4 deletions features/step_definitions/tag_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@
end
end

Given /^a set of tags for tag sort by use exists$/ do
Given "a set of tags for tag sort by use exists" do
hash = {
"10 uses" => 10,
"8 uses" => 8,
"also 8 uses" => 8,
"5 uses" => 5,
"2 uses" => 2,
"0 uses" => 0
"0 uses" => 0,
}

# Create tags with specified number of uses
Expand All @@ -75,8 +75,8 @@
tag.taggings_count = uses
end

step %{all indexing jobs have been run}
step %{the periodic tag count task is run}
step "all indexing jobs have been run"
step "the periodic tag count task is run"
end

Given /^I have a canonical "([^\"]*)" fandom tag named "([^\"]*)"$/ do |media, fandom|
Expand Down
1 change: 0 additions & 1 deletion features/tags_and_wrangling/tag_search.feature
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ Feature: Search Tags

Scenario: Search and sort by Uses in descending and ascending order
Given a set of tags for tag sort by use exists
And all indexing jobs have been run
When I am on the search tags page
And I fill in "Tag name" with "uses"
And I select "Uses" from "Sort by"
Expand Down
14 changes: 7 additions & 7 deletions spec/models/tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@
end
end

context ".write_redis_to_databaser" do
context "write_redis_to_database" do
let(:tag) { create(:fandom) }
let!(:work) { create(:work, fandom_string: tag.name) }

before do
Tag.write_redis_to_database
RedisJobSpawner.perform_now("TagCountUpdateJob")
tag.reload
end

Expand All @@ -104,7 +104,7 @@
# Check if redis has flagged this tag for an update to the database.
expect(REDIS_GENERAL.sismember("tag_update", tag.id)).to eq true

Tag.write_redis_to_database
RedisJobSpawner.perform_now("TagCountUpdateJob")
tag.reload

# Actual number of taggings has not changed though count cache has.
Expand All @@ -120,7 +120,7 @@
# Check if redis has flagged this tag for an update to the database.
expect(REDIS_GENERAL.sismember("tag_update", tag.id)).to eq true

Tag.write_redis_to_database
RedisJobSpawner.perform_now("TagCountUpdateJob")
tag.reload

expect(tag.taggings_count_cache).to eq 2
Expand All @@ -133,15 +133,15 @@
REDIS_GENERAL.set("tag_update_#{tag.id}_value", "")
REDIS_GENERAL.sadd("tag_update", tag.id)

Tag.write_redis_to_database
RedisJobSpawner.perform_now("TagCountUpdateJob")

expect(tag.reload.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 { Tag.write_redis_to_database }
expect { RedisJobSpawner.perform_now("TagCountUpdateJob") }
.to add_to_reindex_queue(tag.reload, :main)
end

Expand All @@ -150,7 +150,7 @@
create(:work, fandom_string: tag.name)
end

expect { Tag.write_redis_to_database }
expect { RedisJobSpawner.perform_now("TagCountUpdateJob") }
.to add_to_reindex_queue(tag.reload, :main)
end
end
Expand Down

0 comments on commit 7c55cd8

Please sign in to comment.