Skip to content

Conversation

@Snoopynha
Copy link

Pull Request Checklist

Issue

https://otwarchive.atlassian.net/browse/AO3-7294

Purpose

This PR addresses the accumulation of "bookmark-only" tags in wrangler bins. Sometimes, tags that are only used on bookmarks (and have zero works) get assigned a specific type (like Character or Relationship) or get attached to a Fandom. This clutters the wrangling interface with tags that shouldn't be wrangled yet.

Changes implemented:

1. New Rake Task (tags:reset_bookmark_only):

  • Identifies tags that are non-canonical, non-synonymous, and have zero works (taggings_count_cache: 0).
  • Checks if these tags have been assigned a type other than 'Tag' (Unsorted) OR if they have parent associations (common_taggings).
  • Resets the type to 'Tag' (Unsorted) and removes all parent associations.

2. Scheduled Maintenance:

  • Added the task to config/schedule.rb to run quarterly, ensuring the bins stay clean automatically over time.

Technical Notes:

  • Performance: Uses find_each (batch size 1000) to avoid memory spikes when processing large numbers of tags.
  • Database Efficiency: Uses delete_all for associations and update_columns for the tag itself. This intentionally bypasses ActiveRecord callbacks to prevent triggering expensive Elasticsearch/Redis re-indexing for every single tag reset during bulk maintenance.
  • Testing: Added a comprehensive spec file (spec/lib/tasks/reset_bookmark_tags_spec.rb) covering scenarios for incorrect tags, legitimate work tags, and canonical tags.

Testing Instructions

Prerequisites:

You will need access to the Rails console (bundle exec rails c) or the ability to run Rake tasks.

Steps to Verify:

1. Create a "Dirty" Tag (The Target):

  • Create a generic tag (e.g., "Test Dirty Bookmark Tag").
  • Ensure it has 0 works.
  • Edit the tag and change its type to Character.
  • Wrangle it to a Fandom (e.g., "Test Fandom").
  • Result: This tag is now "dirty" (Bookmark-only but categorized).

2. Create a "Control" Tag (The Innocent):

  • Create another tag (e.g., "Test Work Tag").
  • Add it to at least 1 work.
  • Edit the tag, make it a Character, and wrangle it to a Fandom.
  • Result: This is a legitimate tag that should NOT be touched.

3. Run the Task:

  • Run: bundle exec rake tags:reset_bookmark_only

4. Verify Results:

  • Check the "Dirty" tag: It should now be listed as Unsorted (Type: Tag) and should not have any Fandom listed.
  • Check the "Control" tag: It should still be a Character and still belong to its Fandom.

Credit

Snoopynha
(She/Her)

*On Jira for assign the issues: Camilly Vitória Barbosa dos Santos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant