From 27d048db0c822d35ad7e5dcc86865f46c99fede9 Mon Sep 17 00:00:00 2001 From: iglocska Date: Tue, 22 Jan 2019 08:28:15 +0100 Subject: [PATCH] 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 --- app/Controller/EventsController.php | 3 ++- app/Model/Attribute.php | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Controller/EventsController.php b/app/Controller/EventsController.php index ea2744295..fbc6947a8 100644 --- a/app/Controller/EventsController.php +++ b/app/Controller/EventsController.php @@ -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); } diff --git a/app/Model/Attribute.php b/app/Model/Attribute.php index 2bc463f5f..acaecf4d4 100644 --- a/app/Model/Attribute.php +++ b/app/Model/Attribute.php @@ -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;