Browse Source

Maintenance: Increase speed of storage usage calculation.

Martin Edenhofer 4 years ago
parent
commit
8e85508fa4

+ 1 - 1
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']

+ 2 - 2
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