Skip to content

Commit

Permalink
Merge pull request #16425 from carbonin/add_disabled_tag_value_purging
Browse files Browse the repository at this point in the history
Add purging for vim_performance_tag_values with disabled tags
(cherry picked from commit c8e9b92)

https://bugzilla.redhat.com/show_bug.cgi?id=1512705
  • Loading branch information
gtanzillo authored and simaishi committed Nov 14, 2017
1 parent a1b73ac commit bf567e7
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tools/purge_orphaned_tag_values.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")

0 comments on commit bf567e7

Please sign in to comment.