From e04a60eb67c81f39944b417c450290ee74deea68 Mon Sep 17 00:00:00 2001 From: Nick Carboni Date: Wed, 8 Nov 2017 17:28:58 -0500 Subject: [PATCH] Add purging for vim_performance_tag_values with disabled tags When a user stops collecting C&U data for a particular tag category, the records hang around in vim_performance_tag_values until they are purged by date. This commit adds an option to the purge_orphaned_tag_values.rb tool to remove such values immediately. https://bugzilla.redhat.com/show_bug.cgi?id=1510484 --- tools/purge_orphaned_tag_values.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tools/purge_orphaned_tag_values.rb b/tools/purge_orphaned_tag_values.rb index 0bed9ab43d8..3eb9687de40 100755 --- a/tools/purge_orphaned_tag_values.rb +++ b/tools/purge_orphaned_tag_values.rb @@ -7,6 +7,7 @@ banner "Purge orphaned vim_performance_tag_values records.\n\nUsage: ruby #{$0} [options]\n\nOptions:\n\t" opt :search_window, "Window of records to scan when finding orpahns", :default => 1000 opt :delete_window, "Window of orphaned records to delete at once", :default => 50 + opt :purge_disabled_tag_values, "Also remove values for tags which are set to not collect data anymore" end Trollop.die :search_window, "must be a number greater than 0" if opts[:search_window] <= 0 Trollop.die :delete_window, "must be a number greater than 0" if opts[:delete_window] <= 0 @@ -63,6 +64,27 @@ def log(msg) pbar.finish log("Deleting orphaned tag values...Complete") end + + deleted_ids = nil + + if opts[:purge_disabled_tag_values] + query = VimPerformanceTagValue.where.not(:category => Classification.category_names_for_perf_by_tag).select(:id) + + log("Deleting tag values for disabled tags...") + total_disabled_count = query.count + pbar = ProgressBar.create(:title => "Deleting disabled tag values", :total => total_disabled_count, :autofinish => false) + + loop do + batch_ids = query.limit(opts[:delete_window]) + count = VimPerformanceTagValue.where(:id => batch_ids).delete_all + + pbar.progress += count + break if count == 0 + end + + pbar.finish + log("Deleting tag values for disabled tags...Complete - #{formatter.number_with_delimiter(total_disabled_count)} records") + end end log("Purging orphaned tag values...Complete")