Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Dashboard sql optimization #241

Open
ruebot opened this issue Jan 8, 2019 · 1 comment
Open

Dashboard sql optimization #241

ruebot opened this issue Jan 8, 2019 · 1 comment

Comments

@ruebot
Copy link
Member

ruebot commented Jan 8, 2019

We have a couple really slow queries on our dashboard that causes a very slow page load.

These two are the main culprits:

def get_largest_collection
largest_collection = WasapiFile.group(:user_id)
.group(:collection_id)
.sum(:size)
.max_by { |_k, v| v }
number_to_human_size(largest_collection[1])
end

883.0ms: SELECT SUM("wasapi_files"."size") AS sum_size, "wasapi_files"."user_id" AS wasapi_files_user_id, "wasapi_files"."collection_id" AS wasapi_files_collection_id FROM "wasapi_files" GROUP BY "wasapi_files"."user_id", "wasapi_files"."collection_id";

def get_total_number_of_warcs
WasapiFile.distinct.count(:filename)
end

22309.8ms: SELECT COUNT(DISTINCT "wasapi_files"."filename") FROM "wasapi_files";
@ruebot
Copy link
Member Author

ruebot commented Jan 8, 2019

SELECT COUNT(*) FROM (SELECT DISTINCT "wasapi_files"."filename" FROM "wasapi_files") AS temp;

Takes the get_total_number_of_warcs query from ~22309.8ms to 1706.4ms

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant