note number index
This commit is contained in:
@@ -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()) {
|
||||
|
||||
@@ -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) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user