Skip to content

Commit

Permalink
Merge pull request #69 from WeareJH/feature/adding-some-indexes-to-op…
Browse files Browse the repository at this point in the history
…timise-table-search

Adding some indexes for common conditions used for searching
  • Loading branch information
bartoszkubicki authored Jan 2, 2025
2 parents 35de3a5 + 85d76aa commit 55f67b5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 36 additions & 0 deletions src/Setup/UpgradeSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Jh\Import\Setup;

use Magento\Framework\DB\Adapter\AdapterInterface;
use Magento\Framework\DB\Ddl\Table;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\UpgradeSchemaInterface;

use function array_key_exists;

/**
* @author Aydin Hassan <[email protected]>
*/
Expand Down Expand Up @@ -305,6 +308,39 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
$setup->getConnection()->createTable($csvArchiveTable);
}

if (version_compare($context->getVersion(), '2.5.6', '<')) {
$connection = $setup->getConnection();
$tableName = $setup->getTable('jh_import_history');
$fieldName = 'import_name';
$indexName = $setup->getIdxName($tableName, $fieldName, AdapterInterface::INDEX_TYPE_INDEX);

$indexesList = $connection->getIndexList($tableName);

if (!array_key_exists($indexName, $indexesList)) {
$connection->addIndex(
$tableName,
$indexName,
[$fieldName],
AdapterInterface::INDEX_TYPE_INDEX
);
}

$tableName = $setup->getTable('jh_import_history_item_log');
$fieldName = 'id_value';
$indexName = $setup->getIdxName($tableName, $fieldName, AdapterInterface::INDEX_TYPE_INDEX);

$indexesList = $connection->getIndexList($tableName);

if (!array_key_exists($indexName, $indexesList)) {
$connection->addIndex(
$tableName,
$indexName,
[$fieldName],
AdapterInterface::INDEX_TYPE_INDEX
);
}
}

$setup->endSetup();
}
}
2 changes: 1 addition & 1 deletion src/etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Jh_Import" setup_version="1.8.0"/>
<module name="Jh_Import" setup_version="2.5.6"/>
</config>

0 comments on commit 55f67b5

Please sign in to comment.