diff options
author | syasonik <syasonik@gitlab.com> | 2019-04-17 14:47:50 +0800 |
---|---|---|
committer | syasonik <syasonik@gitlab.com> | 2019-04-24 18:23:03 +0800 |
commit | b209fb6fb21369b381e4a538f2e46ef1b6579aed (patch) | |
tree | eb1027fc49b67ac93aea490acc56d8dcff837245 /lib | |
parent | 64a1fab788b5f5e92626d96795d68799401536b4 (diff) | |
download | gitlab-ce-b209fb6fb21369b381e4a538f2e46ef1b6579aed.tar.gz |
Minor optimization and code clarity
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/metrics_dashboard/project_metrics_inserter.rb | 28 | ||||
-rw-r--r-- | lib/gitlab/metrics_dashboard/sorter.rb | 4 |
2 files changed, 16 insertions, 16 deletions
diff --git a/lib/gitlab/metrics_dashboard/project_metrics_inserter.rb b/lib/gitlab/metrics_dashboard/project_metrics_inserter.rb index 3903bd39912..f4463645d2c 100644 --- a/lib/gitlab/metrics_dashboard/project_metrics_inserter.rb +++ b/lib/gitlab/metrics_dashboard/project_metrics_inserter.rb @@ -18,20 +18,6 @@ module Gitlab private - # Looks for a panel corresponding to the provided metric object. - # If unavailable, inserts one. - # @param panels [Array<Hash>] - # @param metric [PrometheusMetric] - def find_or_create_panel(panels, metric) - panel = find_panel(panels, metric) - return panel if panel - - panel = new_panel(metric) - panels << panel - - panel - end - # Looks for a panel_group corresponding to the provided metric object. # If unavailable, inserts one. # @param panel_groups [Array<Hash>] @@ -46,6 +32,20 @@ module Gitlab panel_group end + # Looks for a panel corresponding to the provided metric object. + # If unavailable, inserts one. + # @param panels [Array<Hash>] + # @param metric [PrometheusMetric] + def find_or_create_panel(panels, metric) + panel = find_panel(panels, metric) + return panel if panel + + panel = new_panel(metric) + panels << panel + + panel + end + # Looks for a metric corresponding to the provided metric object. # If unavailable, inserts one. # @param metrics [Array<Hash>] diff --git a/lib/gitlab/metrics_dashboard/sorter.rb b/lib/gitlab/metrics_dashboard/sorter.rb index 9a8f87fcb6e..59b21d207e1 100644 --- a/lib/gitlab/metrics_dashboard/sorter.rb +++ b/lib/gitlab/metrics_dashboard/sorter.rb @@ -13,13 +13,13 @@ module Gitlab # Sorts the groups in the dashboard by the :priority key def sort_groups!(dashboard) - dashboard[:panel_groups] = dashboard[:panel_groups].sort_by { |group| group[:priority] }.reverse + dashboard[:panel_groups] = dashboard[:panel_groups].sort_by { |group| -group[:priority].to_i } end # Sorts the panels in the dashboard by the :weight key def sort_panels!(dashboard) dashboard[:panel_groups].each do |group| - group[:panels] = group[:panels].sort_by { |panel| panel[:weight] }.reverse + group[:panels] = group[:panels].sort_by { |panel| -panel[:weight].to_i } end end end |