From 226faae8ec20fb2e683e2873358668a381411307 Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 29 Mar 2022 21:06:24 -0500 Subject: [PATCH] BURs: fix tags field not finding all BURs with that tag. Fix the Tags field in the BUR search form not finding all BURs mentioning that tag. Specifically, tags that were part of a mass update, and that were prefixed with `~` or `-` (OR tags and NOT tags), weren't indexed as tags affected by the BUR. This requires re-running script/fixes/064_initialize_bulk_update_request_tags.rb to fix old BURs. --- app/logical/bulk_update_request_processor.rb | 9 ++++----- .../fixes/064_initialize_bulk_update_request_tags.rb | 11 +++++++---- test/unit/bulk_update_request_test.rb | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/logical/bulk_update_request_processor.rb b/app/logical/bulk_update_request_processor.rb index ff2a39814..8235939a6 100644 --- a/app/logical/bulk_update_request_processor.rb +++ b/app/logical/bulk_update_request_processor.rb @@ -196,18 +196,17 @@ class BulkUpdateRequestProcessor end end - # The list of tags in the script. Used for search BURs by tag. - # @return [Tag] the list of tags + # The list of tags in the script. Used to search BURs by tag. + # @return [Array] the list of tags def affected_tags commands.flat_map do |command, *args| case command when :create_alias, :remove_alias, :create_implication, :remove_implication, :rename [args[0], args[1]] when :mass_update - tags = PostQueryBuilder.new(args[0]).tags + PostQueryBuilder.new(args[1]).tags - tags.reject(&:negated).reject(&:optional).reject(&:wildcard).map(&:name) + PostQuery.new(args[0]).tag_names + PostQuery.new(args[1]).tag_names when :nuke - PostQueryBuilder.new(args[0]).tags.map(&:name) + PostQuery.new(args[0]).tag_names when :change_category args[0] end diff --git a/script/fixes/064_initialize_bulk_update_request_tags.rb b/script/fixes/064_initialize_bulk_update_request_tags.rb index a398b9a96..6cb04df63 100755 --- a/script/fixes/064_initialize_bulk_update_request_tags.rb +++ b/script/fixes/064_initialize_bulk_update_request_tags.rb @@ -1,11 +1,14 @@ #!/usr/bin/env ruby -require_relative "../../config/environment" +require_relative "base" -BulkUpdateRequest.transaction do +with_confirmation do BulkUpdateRequest.find_each do |request| request.tags = request.processor.affected_tags - request.save!(validate: false) - puts "bur id=#{request.id} tags=#{request.tags}" + + if request.changed? + request.save!(validate: false) + puts "bur id=#{request.id} added_tags=#{request.tags - request.tags_before_last_save} removed_tags=#{request.tags_before_last_save - request.tags}" + end end end diff --git a/test/unit/bulk_update_request_test.rb b/test/unit/bulk_update_request_test.rb index 8cf6afc4e..f47c5305c 100644 --- a/test/unit/bulk_update_request_test.rb +++ b/test/unit/bulk_update_request_test.rb @@ -546,7 +546,7 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase assert_equal(%w[aaa bbb], @bur.tags) @bur.update!(script: @script) - assert_equal(%w(000 111 222 333 444 aaa bbb ccc ddd eee iii), @bur.tags) + assert_equal(%w(000 111 222 333 444 555 aaa bbb ccc ddd eee fff ggg iii), @bur.tags) end end