New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboard sql optimization #241

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

Comments

Projects
None yet
1 participant
@ruebot
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 ruebot self-assigned this Jan 8, 2019

@ruebot

This comment has been minimized.

Member

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

ruebot added a commit that referenced this issue Jan 8, 2019

ruebot added a commit that referenced this issue Jan 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment