diff --git a/app/jobs/tag_count_update_job.rb b/app/jobs/tag_count_update_job.rb index 87f8e1e139b..15007d2e8d2 100644 --- a/app/jobs/tag_count_update_job.rb +++ b/app/jobs/tag_count_update_job.rb @@ -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 diff --git a/app/models/tag.rb b/app/models/tag.rb index 8620623125c..7f7e5edca3c 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -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 ) diff --git a/features/step_definitions/tag_steps.rb b/features/step_definitions/tag_steps.rb index f726534cf4e..a12e0457f3a 100644 --- a/features/step_definitions/tag_steps.rb +++ b/features/step_definitions/tag_steps.rb @@ -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 @@ -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| diff --git a/features/tags_and_wrangling/tag_search.feature b/features/tags_and_wrangling/tag_search.feature index 5fb6bdba323..a265a293626 100644 --- a/features/tags_and_wrangling/tag_search.feature +++ b/features/tags_and_wrangling/tag_search.feature @@ -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" diff --git a/spec/models/tag_spec.rb b/spec/models/tag_spec.rb index 8be026ad784..567e2ea6761 100644 --- a/spec/models/tag_spec.rb +++ b/spec/models/tag_spec.rb @@ -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 @@ -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. @@ -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 @@ -133,7 +133,7 @@ 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 @@ -141,7 +141,7 @@ 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 @@ -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