note number index

This commit is contained in:
Yuri Kuznetsov
2019-12-13 15:42:47 +02:00
parent 0fb9fe5e4c
commit 113649ba3d
2 changed files with 59 additions and 3 deletions
+2 -2
View File
@@ -396,7 +396,7 @@ class Stream extends \Espo\Core\Services\Base
'orderBy' => 'number',
'order' => 'DESC',
'limit' => $sqLimit,
'useIndex' => 'createdByNumber',
'useIndex' => 'number',
];
if ($user->isPortal()) {
@@ -510,7 +510,7 @@ class Stream extends \Espo\Core\Services\Base
'orderBy' => 'number',
'order' => 'DESC',
'limit' => $sqLimit,
'useIndex' => 'createdByNumber',
'useIndex' => 'number',
];
if ($user->isPortal()) {
+57 -1
View File
@@ -24,9 +24,14 @@ class AfterUpgrade
{
public function run($container)
{
$this->container = $container;
$entityManager = $container->get('entityManager');
$this->populateOpportunityContactId($entityManager);
///$this->populateOpportunityContactId($entityManager);
$this->manageIndexes();
}
protected function populateOpportunityContactId($entityManager)
@@ -63,4 +68,55 @@ class AfterUpgrade
$pdo->query($q);
}
}
protected function manageIndexes()
{
$pdo = $this->container->get('entityManager')->getPdo();
$sth = $pdo->prepare("SHOW INDEX FROM `note`");
$sth->execute();
$rows = [];
while ($row = $sth->fetch()) {
$rows[] = $row;
}
$indexes = [];
foreach ($rows as $item) {
$k = 0;
foreach ($rows as $item2) {
if ($item['Key_name'] === $item2['Key_name']) {
$k++;
}
}
if ($k === 1 && $item['Column_name'] === 'number') {
$indexes[] = $item['Key_name'];
}
}
$isFound = false;
$oldIndexes = [];
foreach ($indexes as $key) {
if ($key === 'UNIQ_NUMBER') {
$isFound = true;
}
}
if (!$isFound) {
try {
$sql = "CREATE UNIQUE INDEX UNIQ_NUMBER ON `note` (`number`)";
$pdo->query($sql);
} catch (\Exception $e) {}
}
foreach ($indexes as $item) {
if ($item === 'UNIQ_NUMBER') continue;
try {
$sql = "DROP INDEX {$item} ON `note`";
$pdo->query($sql);
} catch (\Exception $e) {}
}
}
}