From 41b7daf063daef029524ec245ece6af390ce929b Mon Sep 17 00:00:00 2001 From: Damion Junk Date: Thu, 17 Sep 2020 10:44:14 -0500 Subject: [PATCH 1/5] Adding migrations for jos_auth_link and jos_auth_domain to speed up stat queries. --- .../Migration20200917000000AuthLinkIndex.php | 34 +++++++++++++++++++ ...Migration20200917100000AuthDomainIndex.php | 26 ++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 core/migrations/Migration20200917000000AuthLinkIndex.php create mode 100644 core/migrations/Migration20200917100000AuthDomainIndex.php diff --git a/core/migrations/Migration20200917000000AuthLinkIndex.php b/core/migrations/Migration20200917000000AuthLinkIndex.php new file mode 100644 index 00000000000..a93efa38dbd --- /dev/null +++ b/core/migrations/Migration20200917000000AuthLinkIndex.php @@ -0,0 +1,34 @@ +db->tableExists('#__auth_link')) { + $query = "ALTER TABLE `#__auth_link` ADD INDEX auth_domain_id_idx (auth_domain_id);"; + $this->db->setQuery($query); + $this->db->query(); + + $query = "ALTER TABLE `#__auth_link` ADD INDEX user_id_idx (user_id);"; + $this->db->setQuery($query); + $this->db->query(); + } + } + + public function down() { + if ($this->db->tableExists('#__auth_link')) { + $query = "ALTER TABLE `#__auth_link` DROP INDEX auth_domain_id_idx;"; + $this->db->setQuery($query); + $this->db->query(); + + $query = "ALTER TABLE `#__auth_link` DROP INDEX user_id_idx;"; + $this->db->setQuery($query); + $this->db->query(); + } + } + +} diff --git a/core/migrations/Migration20200917100000AuthDomainIndex.php b/core/migrations/Migration20200917100000AuthDomainIndex.php new file mode 100644 index 00000000000..cdc5ad2ee59 --- /dev/null +++ b/core/migrations/Migration20200917100000AuthDomainIndex.php @@ -0,0 +1,26 @@ +db->tableExists('#__auth_domain')) { + $query = "ALTER TABLE `#__auth_domain` ADD INDEX authenticator_idx (authenticator);"; + $this->db->setQuery($query); + $this->db->query(); + } + } + + public function down() { + if ($this->db->tableExists('#__auth_domain')) { + $query = "ALTER TABLE `#__auth_domain` INDEX authenticator_idx;"; + $this->db->setQuery($query); + $this->db->query(); + } + } + +} From d8403d3bf39162fa6bfd23ba6352589cb35d3fdb Mon Sep 17 00:00:00 2001 From: Damion Junk Date: Thu, 17 Sep 2020 11:24:25 -0500 Subject: [PATCH 2/5] Adding white space to make code less aesthetically pleasing --- .../Migration20200917000000AuthLinkIndex.php | 12 ++++++++---- .../Migration20200917100000AuthDomainIndex.php | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/core/migrations/Migration20200917000000AuthLinkIndex.php b/core/migrations/Migration20200917000000AuthLinkIndex.php index a93efa38dbd..11327fa760c 100644 --- a/core/migrations/Migration20200917000000AuthLinkIndex.php +++ b/core/migrations/Migration20200917000000AuthLinkIndex.php @@ -7,8 +7,10 @@ class Migration202000171000000AuthLinkIndex extends Base { - public function up() { - if ($this->db->tableExists('#__auth_link')) { + public function up() + { + if ($this->db->tableExists('#__auth_link')) + { $query = "ALTER TABLE `#__auth_link` ADD INDEX auth_domain_id_idx (auth_domain_id);"; $this->db->setQuery($query); $this->db->query(); @@ -19,8 +21,10 @@ public function up() { } } - public function down() { - if ($this->db->tableExists('#__auth_link')) { + public function down() + { + if ($this->db->tableExists('#__auth_link')) + { $query = "ALTER TABLE `#__auth_link` DROP INDEX auth_domain_id_idx;"; $this->db->setQuery($query); $this->db->query(); diff --git a/core/migrations/Migration20200917100000AuthDomainIndex.php b/core/migrations/Migration20200917100000AuthDomainIndex.php index cdc5ad2ee59..d7eafb9859d 100644 --- a/core/migrations/Migration20200917100000AuthDomainIndex.php +++ b/core/migrations/Migration20200917100000AuthDomainIndex.php @@ -7,16 +7,20 @@ class Migration202000171000000AuthDomainIndex extends Base { - public function up() { - if ($this->db->tableExists('#__auth_domain')) { + public function up() + { + if ($this->db->tableExists('#__auth_domain')) + { $query = "ALTER TABLE `#__auth_domain` ADD INDEX authenticator_idx (authenticator);"; $this->db->setQuery($query); $this->db->query(); } } - public function down() { - if ($this->db->tableExists('#__auth_domain')) { + public function down() + { + if ($this->db->tableExists('#__auth_domain')) + { $query = "ALTER TABLE `#__auth_domain` INDEX authenticator_idx;"; $this->db->setQuery($query); $this->db->query(); From 819a4caf89a2fffbf12fd9177bc99775ed5244aa Mon Sep 17 00:00:00 2001 From: Damion Junk Date: Thu, 17 Sep 2020 12:13:05 -0500 Subject: [PATCH 3/5] Fixing linter issues. --- .../Migration20200917000000AuthLinkIndex.php | 51 ++++++++++--------- ...Migration20200917100000AuthDomainIndex.php | 39 +++++++------- 2 files changed, 48 insertions(+), 42 deletions(-) diff --git a/core/migrations/Migration20200917000000AuthLinkIndex.php b/core/migrations/Migration20200917000000AuthLinkIndex.php index 11327fa760c..aff072f8b5e 100644 --- a/core/migrations/Migration20200917000000AuthLinkIndex.php +++ b/core/migrations/Migration20200917000000AuthLinkIndex.php @@ -5,34 +5,37 @@ // no direct access defined('_HZEXEC_') or die(); +/** + * Migration script for adding indexes to the #__auth_link table. + **/ class Migration202000171000000AuthLinkIndex extends Base { - public function up() - { - if ($this->db->tableExists('#__auth_link')) - { - $query = "ALTER TABLE `#__auth_link` ADD INDEX auth_domain_id_idx (auth_domain_id);"; - $this->db->setQuery($query); - $this->db->query(); + public function up() + { + if ($this->db->tableExists('#__auth_link')) + { + $query = "ALTER TABLE `#__auth_link` ADD INDEX auth_domain_id_idx (auth_domain_id);"; + $this->db->setQuery($query); + $this->db->query(); - $query = "ALTER TABLE `#__auth_link` ADD INDEX user_id_idx (user_id);"; - $this->db->setQuery($query); - $this->db->query(); - } - } + $query = "ALTER TABLE `#__auth_link` ADD INDEX user_id_idx (user_id);"; + $this->db->setQuery($query); + $this->db->query(); + } + } - public function down() - { - if ($this->db->tableExists('#__auth_link')) - { - $query = "ALTER TABLE `#__auth_link` DROP INDEX auth_domain_id_idx;"; - $this->db->setQuery($query); - $this->db->query(); + public function down() + { + if ($this->db->tableExists('#__auth_link')) + { + $query = "ALTER TABLE `#__auth_link` DROP INDEX auth_domain_id_idx;"; + $this->db->setQuery($query); + $this->db->query(); - $query = "ALTER TABLE `#__auth_link` DROP INDEX user_id_idx;"; - $this->db->setQuery($query); - $this->db->query(); - } - } + $query = "ALTER TABLE `#__auth_link` DROP INDEX user_id_idx;"; + $this->db->setQuery($query); + $this->db->query(); + } + } } diff --git a/core/migrations/Migration20200917100000AuthDomainIndex.php b/core/migrations/Migration20200917100000AuthDomainIndex.php index d7eafb9859d..6edd47b8973 100644 --- a/core/migrations/Migration20200917100000AuthDomainIndex.php +++ b/core/migrations/Migration20200917100000AuthDomainIndex.php @@ -5,26 +5,29 @@ // no direct access defined('_HZEXEC_') or die(); +/** + * Migration script for adding indexes to the #__auth_domain table. + **/ class Migration202000171000000AuthDomainIndex extends Base { - public function up() - { - if ($this->db->tableExists('#__auth_domain')) - { - $query = "ALTER TABLE `#__auth_domain` ADD INDEX authenticator_idx (authenticator);"; - $this->db->setQuery($query); - $this->db->query(); - } - } + public function up() + { + if ($this->db->tableExists('#__auth_domain')) + { + $query = "ALTER TABLE `#__auth_domain` ADD INDEX authenticator_idx (authenticator);"; + $this->db->setQuery($query); + $this->db->query(); + } + } - public function down() - { - if ($this->db->tableExists('#__auth_domain')) - { - $query = "ALTER TABLE `#__auth_domain` INDEX authenticator_idx;"; - $this->db->setQuery($query); - $this->db->query(); - } - } + public function down() + { + if ($this->db->tableExists('#__auth_domain')) + { + $query = "ALTER TABLE `#__auth_domain` DROP INDEX authenticator_idx;"; + $this->db->setQuery($query); + $this->db->query(); + } + } } From 44d6576027a9713e3165ba4784330b31f38254cf Mon Sep 17 00:00:00 2001 From: Damion Junk Date: Thu, 17 Sep 2020 15:19:45 -0500 Subject: [PATCH 4/5] Adding conditional logic for presence/absence of index --- .../Migration20200917000000AuthLinkIndex.php | 36 ++++++++++++------- ...Migration20200917100000AuthDomainIndex.php | 6 ++-- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/core/migrations/Migration20200917000000AuthLinkIndex.php b/core/migrations/Migration20200917000000AuthLinkIndex.php index aff072f8b5e..e82ff7d8af2 100644 --- a/core/migrations/Migration20200917000000AuthLinkIndex.php +++ b/core/migrations/Migration20200917000000AuthLinkIndex.php @@ -14,13 +14,19 @@ public function up() { if ($this->db->tableExists('#__auth_link')) { - $query = "ALTER TABLE `#__auth_link` ADD INDEX auth_domain_id_idx (auth_domain_id);"; - $this->db->setQuery($query); - $this->db->query(); + if (!$this->db->tableHasKey('#__auth_link', 'auth_domain_id_idx')) + { + $query = "ALTER TABLE `#__auth_link` ADD INDEX auth_domain_id_idx (auth_domain_id);"; + $this->db->setQuery($query); + $this->db->query(); + } - $query = "ALTER TABLE `#__auth_link` ADD INDEX user_id_idx (user_id);"; - $this->db->setQuery($query); - $this->db->query(); + if (!$this->db->tableHasKey('#__auth_link', 'user_id_idx')) + { + $query = "ALTER TABLE `#__auth_link` ADD INDEX user_id_idx (user_id);"; + $this->db->setQuery($query); + $this->db->query(); + } } } @@ -28,13 +34,19 @@ public function down() { if ($this->db->tableExists('#__auth_link')) { - $query = "ALTER TABLE `#__auth_link` DROP INDEX auth_domain_id_idx;"; - $this->db->setQuery($query); - $this->db->query(); + if ($this->db->tableHasKey('#__auth_link', 'auth_domain_id_idx')) + { + $query = "ALTER TABLE `#__auth_link` DROP INDEX auth_domain_id_idx;"; + $this->db->setQuery($query); + $this->db->query(); + } - $query = "ALTER TABLE `#__auth_link` DROP INDEX user_id_idx;"; - $this->db->setQuery($query); - $this->db->query(); + if ($this->db->tableHasKey('#__auth_link', 'user_id_idx')) + { + $query = "ALTER TABLE `#__auth_link` DROP INDEX user_id_idx;"; + $this->db->setQuery($query); + $this->db->query(); + } } } diff --git a/core/migrations/Migration20200917100000AuthDomainIndex.php b/core/migrations/Migration20200917100000AuthDomainIndex.php index 6edd47b8973..bfdad7f59a2 100644 --- a/core/migrations/Migration20200917100000AuthDomainIndex.php +++ b/core/migrations/Migration20200917100000AuthDomainIndex.php @@ -12,7 +12,8 @@ class Migration202000171000000AuthDomainIndex extends Base { public function up() { - if ($this->db->tableExists('#__auth_domain')) + if ($this->db->tableExists('#__auth_domain') && + !$this->db->tableHasKey('#__auth_domain', 'authenticator_idx')) { $query = "ALTER TABLE `#__auth_domain` ADD INDEX authenticator_idx (authenticator);"; $this->db->setQuery($query); @@ -22,7 +23,8 @@ public function up() public function down() { - if ($this->db->tableExists('#__auth_domain')) + if ($this->db->tableExists('#__auth_domain') && + $this->db->tableHasKey('#__auth_domain', 'authenticator_idx')) { $query = "ALTER TABLE `#__auth_domain` DROP INDEX authenticator_idx;"; $this->db->setQuery($query); From 283a55e74c2a42cd07655bdb0eac6f7972488fd7 Mon Sep 17 00:00:00 2001 From: Damion Junk Date: Thu, 17 Sep 2020 15:27:24 -0500 Subject: [PATCH 5/5] i just love our linter settings --- core/migrations/Migration20200917100000AuthDomainIndex.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/migrations/Migration20200917100000AuthDomainIndex.php b/core/migrations/Migration20200917100000AuthDomainIndex.php index bfdad7f59a2..ede11966c97 100644 --- a/core/migrations/Migration20200917100000AuthDomainIndex.php +++ b/core/migrations/Migration20200917100000AuthDomainIndex.php @@ -13,7 +13,7 @@ class Migration202000171000000AuthDomainIndex extends Base public function up() { if ($this->db->tableExists('#__auth_domain') && - !$this->db->tableHasKey('#__auth_domain', 'authenticator_idx')) + !$this->db->tableHasKey('#__auth_domain', 'authenticator_idx')) { $query = "ALTER TABLE `#__auth_domain` ADD INDEX authenticator_idx (authenticator);"; $this->db->setQuery($query); @@ -24,7 +24,7 @@ public function up() public function down() { if ($this->db->tableExists('#__auth_domain') && - $this->db->tableHasKey('#__auth_domain', 'authenticator_idx')) + $this->db->tableHasKey('#__auth_domain', 'authenticator_idx')) { $query = "ALTER TABLE `#__auth_domain` DROP INDEX authenticator_idx;"; $this->db->setQuery($query);