fix: [performance] Potential performance fix for older MySQL versions using the wrong index as key during fetchAttributes()

- observer a server prioritising the deleted flag index when filtering attributes, leading to a massive performance loss
- hacky solution to make deleted and object_id (during flattening) indeces unusable
pull/4048/head
iglocska 2019-01-22 08:28:15 +01:00
parent 17943e2533
commit 27d048db0c
2 changed files with 4 additions and 3 deletions

View File

@ -3608,7 +3608,8 @@ class EventsController extends AppController
$options = array(
'conditions' => array('OR' => array('Attribute.value1' => $result['value'], 'Attribute.value2' => $result['value'])),
'fields' => array('Attribute.type', 'Attribute.category', 'Attribute.value', 'Attribute.comment'),
'order' => false
'order' => false,
'flatten' => 1
);
$resultArray[$key]['related'] = $this->Event->Attribute->fetchAttributes($this->Auth->user(), $options);
}

View File

@ -2890,7 +2890,7 @@ class Attribute extends AppModel
$params['conditions']['AND'][] = $options['conditions'];
}
if (empty($options['flatten'])) {
$params['conditions']['AND'][] = array('Attribute.object_id' => 0);
$params['conditions']['AND'][] = array('(Attribute.object_id + 0)' => 0);
}
if (isset($options['order'])) {
$params['order'] = $options['order'];
@ -2902,7 +2902,7 @@ class Attribute extends AppModel
$options['enforceWarninglist'] = false;
}
if (!$user['Role']['perm_sync'] || !isset($options['deleted']) || !$options['deleted']) {
$params['conditions']['AND']['Attribute.deleted'] = 0;
$params['conditions']['AND']['(Attribute.deleted + 0)'] = 0;
}
if (isset($options['group'])) {
$params['group'] = empty($options['group']) ? $options['group'] : false;