Skip to content
Open
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
19 changes: 19 additions & 0 deletions app/jobs/enqueue_bookmarks_tags_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class EnqueueBookmarksTagsJob < ApplicationJob
queue_as :low

def perform
base_scope = Tag.nonsynonymous
.where(canonical: false)

Check warning on line 6 in app/jobs/enqueue_bookmarks_tags_job.rb

View workflow job for this annotation

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 Use 2 (not 16) spaces for indenting an expression in an assignment spanning multiple lines. Raw Output: app/jobs/enqueue_bookmarks_tags_job.rb:6:21: C: Layout/MultilineMethodCallIndentation: Use 2 (not 16) spaces for indenting an expression in an assignment spanning multiple lines.
.where("NOT EXISTS (

Check warning on line 7 in app/jobs/enqueue_bookmarks_tags_job.rb

View workflow job for this annotation

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 Use 2 (not 16) spaces for indenting an expression in an assignment spanning multiple lines. Raw Output: app/jobs/enqueue_bookmarks_tags_job.rb:7:21: C: Layout/MultilineMethodCallIndentation: Use 2 (not 16) spaces for indenting an expression in an assignment spanning multiple lines.
SELECT 1 FROM taggings
WHERE taggings.tagger_id = tags.id
AND taggings.taggable_type IN ('Work', 'ExternalWork')
)")
.limit(5000)

Check warning on line 12 in app/jobs/enqueue_bookmarks_tags_job.rb

View workflow job for this annotation

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 Use 2 (not 16) spaces for indenting an expression in an assignment spanning multiple lines. Raw Output: app/jobs/enqueue_bookmarks_tags_job.rb:12:21: C: Layout/MultilineMethodCallIndentation: Use 2 (not 16) spaces for indenting an expression in an assignment spanning multiple lines.
.pluck(:id)

Check warning on line 13 in app/jobs/enqueue_bookmarks_tags_job.rb

View workflow job for this annotation

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 Use 2 (not 16) spaces for indenting an expression in an assignment spanning multiple lines. Raw Output: app/jobs/enqueue_bookmarks_tags_job.rb:13:21: C: Layout/MultilineMethodCallIndentation: Use 2 (not 16) spaces for indenting an expression in an assignment spanning multiple lines.

base_scope.each_slice(1000) do |batch_ids|
ResetBookmarkTagsJob.perform_later(batch_ids)
end
end
end
23 changes: 23 additions & 0 deletions app/jobs/reset_bookmark_tags_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class ResetBookmarkTagsJob < ApplicationJob
queue_as :low

def perform(tag_ids)
base_scope = Tag.nonsynonymous
.where(canonical: false)

Check warning on line 6 in app/jobs/reset_bookmark_tags_job.rb

View workflow job for this annotation

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 Use 2 (not 16) spaces for indenting an expression in an assignment spanning multiple lines. Raw Output: app/jobs/reset_bookmark_tags_job.rb:6:21: C: Layout/MultilineMethodCallIndentation: Use 2 (not 16) spaces for indenting an expression in an assignment spanning multiple lines.
.where("NOT EXISTS (

Check warning on line 7 in app/jobs/reset_bookmark_tags_job.rb

View workflow job for this annotation

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 Use 2 (not 16) spaces for indenting an expression in an assignment spanning multiple lines. Raw Output: app/jobs/reset_bookmark_tags_job.rb:7:21: C: Layout/MultilineMethodCallIndentation: Use 2 (not 16) spaces for indenting an expression in an assignment spanning multiple lines.
SELECT 1 FROM taggings
WHERE taggings.tagger_id = tags.id
AND taggings.taggable_type IN ('Work', 'ExternalWork')
)")

base_scope.where(id: tag_ids).each do |tag|
has_type = tag.type.present? && tag.type != "Tag"
has_parents = tag.common_taggings.exists?

next unless has_type || has_parents

tag.common_taggings.destroy_all
tag.update(type: "Tag")
end
end
end
7 changes: 7 additions & 0 deletions config/resque_schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,10 @@ disable_admin_post_comments:
description: >-
Disables all comments on admin (news) posts older than the
configured window.

reset_bookmark_tags_job:
cron: "0 0 1 */3 *"
class: "EnqueueBookmarksTagsJob"
queue: low
description: Reset bookmark-only tags to unsorted quarterly

51 changes: 51 additions & 0 deletions spec/jobs/reset_bookmark_tags_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require "spec_helper"

describe ResetBookmarkTagsJob do
describe "#perform" do
it "resets a non-canonical tag with no work uses" do
fandom = create(:fandom, canonical: true)

dirty_tag = create(:tag,
name: "Dirty Tag",
type: "Character",
canonical: false,
taggings_count_cache: 0)

create(:common_tagging, common_tag: dirty_tag, filterable: fandom)
ResetBookmarkTagsJob.perform_now(Tag.pluck(:id))

dirty_tag.reload
expect(dirty_tag.type).to eq("Tag")
expect(dirty_tag.common_taggings.count).to eq(0)
end

it "does not reset a non-canonical tag with work uses" do
fandom = create(:fandom, canonical: true)

work_tag = create(:character,
name: "Work Tag",
type: "Character",
canonical: false,
taggings_count_cache: 5)

create(:common_tagging, common_tag: work_tag, filterable: fandom)
ResetBookmarkTagsJob.perform_now(Tag.pluck(:id))

work_tag.reload
expect(work_tag.common_taggings.count).to eq(1)
expect(work_tag.type).to eq("Character")
end

it "does not reset a canonical tag" do
canonical_tag = create(:fandom,
name: "Official Fandom",
canonical: true)

ResetBookmarkTagsJob.perform_now(Tag.pluck(:id))

canonical_tag.reload
expect(canonical_tag.canonical).to be_truthy
expect(canonical_tag.type).to eq("Fandom")
end
end
end
Loading