Closed dave-mills closed 1 year ago
working on branch optimise_anonymity_check
I have revised two SQLs, pushed latest code in branch optimise_anonymity_check.
I have cloned live db to my local db yesterday. Two revised SQLs took 13ms and 11ms to execute in my local db now.
Below please find BEFORE and AFTER for quick reference.
Some highlights:
BEFORE
-- find number of projects SELECT COUNT(*) from dashboard_project where dashboard_id = 1687878621;
-- find number of organisations SELECT COUNT(DISTINCT (projects.organisation_id)) FROM dashboard_project LEFT JOIN projects on projects.id = dashboard_project.project_id;
AFTER
-- find number of projects SELECT COUNT(DISTINCT project_id) AS number_of_project FROM dashboard_project WHERE dashboard_id = 1687878621;
-- find number of organisations SELECT COUNT(DISTINCT p.organisation_id) AS number_of_organisation FROM dashboard_project AS dp, projects AS p WHERE dp.project_id = p.id AND dp.dashboard_id = 1687878621;
Amazing! Thanks - the Count DISTINCT and INNER JOIN are good things for me to remember in future. 👍
When adding the code the check if there is enough data to present a fully "anonymised" set of "other" institutions' data, the dashboard query goes from ~150ms to ~2.5 seconds. Not huge, but worth exploring to see if it can be optimised.