From 8e85508fa4e86793f996917d2b68b18946460134 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 22 Mar 2021 13:35:01 +0000 Subject: [PATCH] Maintenance: Increase speed of storage usage calculation. --- app/controllers/monitoring_controller.rb | 2 +- spec/requests/integration/monitoring_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/monitoring_controller.rb b/app/controllers/monitoring_controller.rb index d3e2bf8ea..94b545c8c 100644 --- a/app/controllers/monitoring_controller.rb +++ b/app/controllers/monitoring_controller.rb @@ -249,7 +249,7 @@ curl http://localhost/api/v1/monitoring/status?token=XXX end if ActiveRecord::Base.connection_config[:adapter] == 'postgresql' - sql = 'SELECT SUM(CAST(coalesce(size, \'0\') AS INTEGER)) FROM stores WHERE id IN (SELECT MAX(id) FROM stores GROUP BY store_file_id)' + sql = 'SELECT SUM(CAST(coalesce(size, \'0\') AS INTEGER)) FROM stores' records_array = ActiveRecord::Base.connection.exec_query(sql) if records_array[0] && records_array[0]['sum'] sum = records_array[0]['sum'] diff --git a/spec/requests/integration/monitoring_spec.rb b/spec/requests/integration/monitoring_spec.rb index 2e710857f..9d4cab116 100644 --- a/spec/requests/integration/monitoring_spec.rb +++ b/spec/requests/integration/monitoring_spec.rb @@ -180,8 +180,8 @@ RSpec.describe 'Monitoring', type: :request do expect(json_response['storage']).to be_truthy expect(json_response['storage']).to be_key('kB') - # check if the stores got summarized. value should be the same because the file has the same fingerprint - expect(json_response['storage']['kB']).to eq(first_json_response_kb) + # check if the stores got summarized. + expect(json_response['storage']['kB']).to eq(first_json_response_kb * 2) expect(json_response['storage']).to be_key('MB') expect(json_response['storage']).to be_key('GB') else