Class: Debloater::Engine
- Inherits:
-
Object
- Object
- Debloater::Engine
- Includes:
- Helpers
- Defined in:
- lib/debloater/engine.rb
Instance Method Summary collapse
-
#initialize(conn, confirm: true, min_mb: 50, max_density: 0.75) ⇒ Engine
constructor
A new instance of Engine.
- #run ⇒ Object
Methods included from Helpers
Constructor Details
#initialize(conn, confirm: true, min_mb: 50, max_density: 0.75) ⇒ Engine
Returns a new instance of Engine.
9 10 11 12 13 14 |
# File 'lib/debloater/engine.rb', line 9 def initialize(conn, confirm: true, min_mb: 50, max_density: 0.75) @conn = conn @confirm = confirm @min_mb = min_mb @max_density = max_density end |
Instance Method Details
#run ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/debloater/engine.rb', line 17 def run debloated_indices = [] Index.each(@conn) do |index| if index.pkey? _log "Skipping primary key index '#{index.name}'" next end unless index.valid? _log "Skipping invalid (non-Btree) index '#{index.name}'" next end puts format('%<name>-65s %<size>10d %<frag>3d pct %<bloat>6d MB' % { name: index.name, size: index.size, frag: (100 - index.density * 100).to_i, bloat: index.bloat, }) if index.bloat < @min_mb || index.density > @max_density _log "Skipping non-bloated index '#{index.name}'" next end if @confirm $stderr.write "debloat this index? [y/N] " next unless $stdin.gets.strip =~ /^y$/i end index.debloat! debloated_indices << index end debloated_indices end |