mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 23:16:03 +00:00
orm useIndex change
This commit is contained in:
@@ -57,7 +57,7 @@ abstract class Base
|
||||
'customHaving',
|
||||
'skipTextColumns',
|
||||
'maxTextColumnsLength',
|
||||
'useIndexList',
|
||||
'useIndex',
|
||||
];
|
||||
|
||||
protected static $sqlOperators = [
|
||||
@@ -386,9 +386,14 @@ abstract class Base
|
||||
}
|
||||
|
||||
$indexKeyList = null;
|
||||
if (!empty($params['useIndexList']) && $this->metadata) {
|
||||
$indexList = $params['useIndex'] ?? null;
|
||||
|
||||
if (!empty($indexList) && $this->metadata) {
|
||||
$indexKeyList = [];
|
||||
foreach ($params['useIndexList'] as $indexName) {
|
||||
if (is_string($indexList)) {
|
||||
$indexList = [$indexList];
|
||||
}
|
||||
foreach ($indexList as $indexName) {
|
||||
$indexKey = $this->metadata->get($entityType, ['indexes', $indexName, 'key']);
|
||||
if ($indexKey) {
|
||||
$indexKeyList[] = $indexKey;
|
||||
@@ -1819,8 +1824,34 @@ abstract class Base
|
||||
|
||||
$midAlias = $alias . 'Middle';
|
||||
|
||||
$indexKeyList = null;
|
||||
$indexList = $params['useIndex'] ?? null;
|
||||
|
||||
if ($indexList && $this->metadata) {
|
||||
$indexKeyList = [];
|
||||
if (is_string($indexList)) {
|
||||
$indexList = [$indexList];
|
||||
}
|
||||
foreach ($indexList as $indexName) {
|
||||
$indexKey = $this->metadata->get($entity->getEntityType(), ['relations', $relationName, 'indexes', $indexName, 'key']);
|
||||
if ($indexKey) {
|
||||
$indexKeyList[] = $indexKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$indexPart = '';
|
||||
|
||||
if ($indexKeyList && count($indexKeyList)) {
|
||||
$sanitizedIndexList = [];
|
||||
foreach ($indexKeyList as $indexKey) {
|
||||
$sanitizedIndexList[] = '`' . $this->sanitizeIndexName($indexKey) . '`';
|
||||
}
|
||||
$indexPart = " USE INDEX (".implode(', ', $sanitizedIndexList).")";
|
||||
}
|
||||
|
||||
$sql =
|
||||
"{$prefix}JOIN `{$relTable}` AS `{$midAlias}` ON {$this->toDb($entity->getEntityType())}." . $this->toDb($key) . " = {$midAlias}." . $this->toDb($nearKey)
|
||||
"{$prefix}JOIN `{$relTable}` AS `{$midAlias}`{$indexPart} ON {$this->toDb($entity->getEntityType())}." . $this->toDb($key) . " = {$midAlias}." . $this->toDb($nearKey)
|
||||
. " AND "
|
||||
. "{$midAlias}.deleted = " . $this->pdo->quote(0);
|
||||
|
||||
|
||||
@@ -71,12 +71,12 @@ class Email extends \Espo\Core\SelectManagers\Base
|
||||
$skipIndex = true;
|
||||
}
|
||||
if (!$skipIndex) {
|
||||
$result['useIndexList'] = ['dateSent'];
|
||||
$result['useIndex'] = 'dateSent';
|
||||
}
|
||||
}
|
||||
|
||||
if ($folderId === 'drafts') {
|
||||
$result['useIndexList'] = ['createdById'];
|
||||
$result['useIndex'] = 'createdById';
|
||||
}
|
||||
|
||||
if ($folderId !== 'drafts') {
|
||||
|
||||
@@ -386,7 +386,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
'orderBy' => 'number',
|
||||
'order' => 'DESC',
|
||||
'limit' => $sqLimit,
|
||||
'useIndexList' => ['createdByNumber'],
|
||||
'useIndex' => 'createdByNumber',
|
||||
];
|
||||
|
||||
if ($user->isPortal()) {
|
||||
@@ -484,7 +484,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
'orderBy' => 'number',
|
||||
'order' => 'DESC',
|
||||
'limit' => $sqLimit,
|
||||
'useIndexList' => ['createdByNumber'],
|
||||
'useIndex' => 'createdByNumber',
|
||||
];
|
||||
|
||||
if ($user->isPortal()) {
|
||||
|
||||
Reference in New Issue
Block a user