Skip to content

Commit e0cc94c

Browse files
committed
Improve output readability
* tableize the results * add clarification when it's count mode * add purging/done bookends for purging large tables
1 parent 3551ae6 commit e0cc94c

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

tools/purge_orphans.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
def purge_by_orphaned(klass, fk, window, purge_mode)
1818
klass.include PurgingMixin
1919
klass.define_method(:purge_method) { :destroy }
20-
klass.purge_by_orphaned(fk, window, purge_mode).tap { |total| puts "#{purge_mode == :count ? 'Would purge' : 'Purged'}: #{klass}: #{total} rows" }
20+
klass.purge_by_orphaned(fk, window, purge_mode)
2121
end
2222

2323
CLASSES_TO_PURGE = [
@@ -32,13 +32,24 @@ def purge_by_orphaned(klass, fk, window, purge_mode)
3232
SecurityContext, :resource, 1000
3333
]
3434

35+
puts "\nNote: Count mode was provided. No changes are being made. Use --mode purge to purge the rows.\n" if purge_mode == :count
36+
puts
37+
results = [["Class", purge_mode == :count ? "Orphan Count" : "Purged Rows"]]
3538
_result, bm = Benchmark.realtime_block("TotalTime") do
39+
3640
CLASSES_TO_PURGE.each_slice(3) do |klass, fk, window|
3741
Benchmark.realtime_block(klass.name) do
38-
purge_by_orphaned(klass, fk, window, purge_mode)
42+
print "Purging #{klass.name}..."
43+
purge_by_orphaned(klass, fk, window, purge_mode).tap { |result| results << [klass, result] }
44+
puts "Done!"
3945
end
4046
end
4147
nil
4248
end
43-
puts "Timing by model:"
44-
pp bm
49+
puts "\nResults:\n\n"
50+
51+
puts results.tableize
52+
puts
53+
54+
puts "Timing by class:\n\n"
55+
puts bm.transform_values { |v| v.round(6) }.to_a.unshift(["Model", "Time (s)"]).tableize

0 commit comments

Comments
 (0)