Skip to content

Commit

Permalink
Merge pull request #38 from webrgp/patch-1
Browse files Browse the repository at this point in the history
Add table indexes to improve read performance
  • Loading branch information
internetztube authored Oct 4, 2024
2 parents 75a6101 + 731caaa commit 43d3ea8
Showing 1 changed file with 45 additions and 0 deletions.
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],
];
}
}

0 comments on commit 43d3ea8

Please sign in to comment.