From 8d2124bf1c626c61b81f81c5d8386b8091b52c55 Mon Sep 17 00:00:00 2001 From: Tomasz Wolniewicz Date: Wed, 3 Jul 2024 10:28:39 +0200 Subject: [PATCH] more DB optimisations --- core/Federation.php | 4 ++-- schema/2_1_1-2_1_2.sql | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/Federation.php b/core/Federation.php index a658ae9e5..60e011bbd 100644 --- a/core/Federation.php +++ b/core/Federation.php @@ -89,8 +89,8 @@ private function downloadStatsCore($detail = '') $cohesionQuery = [ 'ORGANISATIONS' => "SELECT profile.inst_id AS inst_id, downloads.device_id AS dev_id, sum(downloads.downloads_user) AS dl_user, sum(downloads.downloads_silverbullet) as dl_sb, sum(downloads.downloads_admin) AS dl_admin FROM downloads JOIN profile ON downloads.profile_id=profile.profile_id JOIN institution ON profile.inst_id=institution.inst_id WHERE institution.country = ? GROUP BY profile.inst_id, downloads.device_id", 'PROFILES' => "SELECT profile.inst_id AS inst_id, profile.profile_id AS profile_id, downloads.device_id AS dev_id, sum(downloads.downloads_user) AS dl_user, sum(downloads.downloads_silverbullet) as dl_sb, sum(downloads.downloads_admin) AS dl_admin FROM downloads JOIN profile ON downloads.profile_id=profile.profile_id JOIN institution ON profile.inst_id=institution.inst_id WHERE institution.country = ? GROUP BY profile.inst_id, profile.profile_id, downloads.device_id", - 'FEDERATION' => "SELECT downloads.device_id as dev_id, sum(downloads.downloads_user) as dl_user, sum(downloads.downloads_silverbullet) AS dl_sb, sum(downloads.downloads_admin) as dl_admin FROM profile, institution, downloads WHERE profile.inst_id = institution.inst_id AND institution.country = ? AND profile.profile_id = downloads.profile_id group by device_id", - 'NONE' => "SELECT downloads.device_id as dev_id, sum(downloads.downloads_user) as dl_user, sum(downloads.downloads_silverbullet) AS dl_sb, sum(downloads.downloads_admin) as dl_admin FROM profile, institution, downloads WHERE profile.inst_id = institution.inst_id AND institution.country = ? AND profile.profile_id = downloads.profile_id group by device_id" + 'FEDERATION' => "SELECT downloads.device_id AS dev_id, sum(downloads.downloads_user) AS dl_user, sum(downloads.downloads_silverbullet) AS dl_sb, sum(downloads.downloads_admin) AS dl_admin FROM profile JOIN institution ON profile .inst_id = institution.inst_id JOIN downloads ON profile.profile_id = downloads.profile_id WHERE institution.country = ? AND profile.profile_id = downloads.profile_id GROUP BY device_id", + 'NONE' => "SELECT downloads.device_id as dev_id, sum(downloads.downloads_user) as dl_user, sum(downloads.downloads_silverbullet) AS dl_sb, sum(downloads.downloads_admin) as dl_admin FROM profile JOIN institution ON profile .inst_id = institution.inst_id JOIN downloads ON profile.profile_id = downloads.profile_id WHERE profile.inst_id = institution.inst_id AND institution.country = ? AND profile.profile_id = downloads.profile_id group by device_id" ]; // first, find out which profiles belong to this federation $downloadsList = $this->databaseHandle->exec($cohesionQuery[$detail], "s", $this->tld); diff --git a/schema/2_1_1-2_1_2.sql b/schema/2_1_1-2_1_2.sql index 49c72a783..c2ea434e1 100644 --- a/schema/2_1_1-2_1_2.sql +++ b/schema/2_1_1-2_1_2.sql @@ -27,10 +27,15 @@ UPDATE profile_option_dict SET flag='SPECIFIC' WHERE name = 'device-specific:geteduroam'; UPDATE profile_option_dict SET flag='SPECIFIC' WHERE name = 'device-specific:geantlink'; +ALTER TABLE federation_option ADD KEY federation_id (federation_id); ALTER TABLE profile_option ADD KEY profile_id (profile_id); +ALTER TABLE profile_option ADD KEY device_id (device_id); ALTER TABLE profile ADD KEY showtime (showtime); ALTER TABLE profile ADD KEY sufficient_config (sufficient_config); ALTER TABLE profile ADD KEY openroaming (openroaming); ALTER TABLE institution ADD KEY country (country); ALTER TABLE institution ADD KEY external_db_id (external_db_id); ALTER TABLE institution ADD KEY external_db_syncstate (external_db_syncstate); +ALTER TABLE invitations ADD KEY cat_institution_id (cat_institution_id); +ALTER TABLE invitations ADD KEY invite_created (invite_created); +ALTER TABLE invitations ADD KEY used (used);