Skip to content

Commit

Permalink
DRY invalid indexes [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Aug 31, 2018
1 parent 7dc97c6 commit 8415327
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
2 changes: 1 addition & 1 deletion app/controllers/pg_hero/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def index
@sequence_danger = @database.sequence_danger(threshold: (params[:sequence_threshold] || 0.9).to_f, sequences: @readable_sequences)

@indexes = @database.indexes
@invalid_indexes = @indexes.select { |i| !i[:valid] }
@invalid_indexes = @database.invalid_indexes(indexes: @indexes)
@duplicate_indexes = @database.duplicate_indexes(indexes: @indexes)

if @query_stats_enabled
Expand Down
28 changes: 7 additions & 21 deletions lib/pghero/methods/indexes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,27 +114,13 @@ def last_stats_reset_time
SQL
end

# TODO use indexes method
def invalid_indexes
select_all <<-SQL
SELECT
n.nspname AS schema,
c.relname AS index,
pg_get_indexdef(i.indexrelid) AS definition
FROM
pg_catalog.pg_class c,
pg_catalog.pg_namespace n,
pg_catalog.pg_index i
WHERE
i.indisvalid = false
AND i.indexrelid = c.oid
AND c.relnamespace = n.oid
AND n.nspname != 'pg_catalog'
AND n.nspname != 'information_schema'
AND n.nspname != 'pg_toast'
ORDER BY
c.relname
SQL
def invalid_indexes(indexes: nil)
indexes = (indexes || self.indexes).select { |i| !i[:valid] }
indexes.each do |index|
# map name -> index for backward compatibility
index[:index] = index[:name]
end
indexes
end

# TODO parse array properly
Expand Down

0 comments on commit 8415327

Please sign in to comment.