diff options
author | Peter Leitzen <pleitzen@gitlab.com> | 2019-04-29 10:25:31 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2019-04-29 10:25:31 +0000 |
commit | 80fec5c3295977c5559c420f51fd774391d3ca91 (patch) | |
tree | 3f8dab112c87e54ae591425a2f739aa6f7410660 | |
parent | ab9910f7a5fe4981b330c3886865397fd066108d (diff) | |
download | gitlab-ce-80fec5c3295977c5559c420f51fd774391d3ca91.tar.gz |
Load environment metrics only for JSON endpoint
When showing the HTML version of the environment metrics we don't need
to fetch their metrics because we don't use them anymore on the HTML
version.
We use additional_metrics.json endpoint now.
-rw-r--r-- | app/controllers/projects/environments_controller.rb | 8 | ||||
-rw-r--r-- | spec/controllers/projects/environments_controller_spec.rb | 8 |
2 files changed, 8 insertions, 8 deletions
diff --git a/app/controllers/projects/environments_controller.rb b/app/controllers/projects/environments_controller.rb index 1f619c8fd2f..4aa572ade73 100644 --- a/app/controllers/projects/environments_controller.rb +++ b/app/controllers/projects/environments_controller.rb @@ -135,13 +135,13 @@ class Projects::EnvironmentsController < Projects::ApplicationController end def metrics - # Currently, this acts as a hint to load the metrics details into the cache - # if they aren't there already - @metrics = environment.metrics || {} - respond_to do |format| format.html format.json do + # Currently, this acts as a hint to load the metrics details into the cache + # if they aren't there already + @metrics = environment.metrics || {} + render json: @metrics, status: @metrics.any? ? :ok : :no_content end end diff --git a/spec/controllers/projects/environments_controller_spec.rb b/spec/controllers/projects/environments_controller_spec.rb index c1c4be45168..a62422d0229 100644 --- a/spec/controllers/projects/environments_controller_spec.rb +++ b/spec/controllers/projects/environments_controller_spec.rb @@ -342,11 +342,9 @@ describe Projects::EnvironmentsController do end context 'when environment has no metrics' do - before do - expect(environment).to receive(:metrics).and_return(nil) - end - it 'returns a metrics page' do + expect(environment).not_to receive(:metrics) + get :metrics, params: environment_params expect(response).to be_ok @@ -354,6 +352,8 @@ describe Projects::EnvironmentsController do context 'when requesting metrics as JSON' do it 'returns a metrics JSON document' do + expect(environment).to receive(:metrics).and_return(nil) + get :metrics, params: environment_params(format: :json) expect(response).to have_gitlab_http_status(204) |