-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from webrgp/patch-1
Add table indexes to improve read performance
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/migrations/m241004_144031_optimize_index_elementrelations_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace internetztube\elementRelations\migrations; | ||
|
||
use Craft; | ||
use craft\db\Migration; | ||
use internetztube\elementRelations\records\ElementRelationsCacheRecord; | ||
|
||
/** | ||
* m241004_144031_optimize_index_elementrelations_table migration. | ||
*/ | ||
class m241004_144031_optimize_index_elementrelations_table extends Migration | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function safeUp(): bool | ||
{ | ||
foreach ($this->_indexes() as $index) { | ||
$this->createIndexIfMissing(...$index); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function safeDown(): bool | ||
{ | ||
foreach ($this->_indexes() as $index) { | ||
$this->dropIndexIfExists(...$index); | ||
} | ||
return true; | ||
} | ||
|
||
private function _indexes(): array | ||
{ | ||
return [ | ||
[ElementRelationsCacheRecord::tableName(), ['sourceElementId', 'sourceSiteId'], false], | ||
[ElementRelationsCacheRecord::tableName(), ['targetElementId', 'targetSiteId'], false], | ||
[ElementRelationsCacheRecord::tableName(), ['sourcePrimaryOwnerId'], false], | ||
]; | ||
} | ||
} |