Skip to content

Commit

Permalink
more DB optimisations
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Wolniewicz committed Jul 3, 2024
1 parent 5fd9caf commit 8d2124b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/Federation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions schema/2_1_1-2_1_2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 8d2124b

Please sign in to comment.