Skip to content

Commit bfe8d87

Browse files
authoredOct 29, 2021
Fix sorting on Space Table (#397)
1 parent 8cd4973 commit bfe8d87

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed
 

‎app/controllers/pg_hero/home_controller.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,15 @@ def space
8484
if @space_stats_enabled
8585
space_growth = @database.space_growth(days: @days, relation_sizes: @relation_sizes)
8686
@growth_bytes_by_relation = Hash[ space_growth.map { |r| [[r[:schema], r[:relation]], r[:growth_bytes]] } ]
87-
case params[:sort]
88-
when "growth"
87+
if params[:sort] == "growth"
8988
@relation_sizes.sort_by! { |r| s = @growth_bytes_by_relation[[r[:schema], r[:relation]]]; [s ? 0 : 1, -s.to_i, r[:schema], r[:relation]] }
90-
when "name"
91-
@relation_sizes.sort_by! { |r| r[:relation] || r[:table] }
9289
end
9390
end
9491

92+
if params[:sort] == "name"
93+
@relation_sizes.sort_by! { |r| r[:relation] || r[:table] }
94+
end
95+
9596
across = params[:across].to_s.split(",")
9697
@unused_indexes = @database.unused_indexes(max_scans: 0, across: across)
9798
@unused_index_names = Set.new(@unused_indexes.map { |r| r[:index] })

‎app/views/pg_hero/home/space.html.erb

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040
<table class="table space-table">
4141
<thead>
4242
<tr>
43-
<th><%= link_to "Relation", {sort: "name"} %></th>
44-
<th style="width: 15%;"><%= link_to "Size", {} %></th>
43+
<th><%= link_to (params[:tables] ? "Table" : "Relation"), {sort: "name", tables: params[:tables]} %></th>
44+
<th style="width: 15%;"><%= link_to "Size", {tables: params[:tables]} %></th>
4545
<% if @space_stats_enabled %>
46-
<th style="width: 15%;"><%= link_to "#{@days}d Growth", {sort: "growth"} %></th>
46+
<th style="width: 15%;"><%= link_to "#{@days}d Growth", {sort: "growth", tables: params[:tables]} %></th>
4747
<% end %>
4848
</tr>
4949
</thead>

0 commit comments

Comments
 (0)