Skip to content

Commit 4542c78

Browse files
committedOct 21, 2019
Mysql-Query Performance continue to optimize
1 parent 411b144 commit 4542c78

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed
 

‎classes/xrowGISTools.php

+15-19
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ static function citiesBySubtree( eZContentObjectTreeNode $node, $params )
1414

1515
$object_state = ($params['object_state']!=null) ? true : false;
1616

17-
$subselect = ($object_state)?"JOIN ezcobj_state_link AS ezlink ON ezlink.contentobject_id = ezobj.id AND ezlink.contentobject_state_id = {$params['object_state']}" : "";
17+
$subselect = ($object_state)?"JOIN ezcobj_state_link AS ezlink ON ezlink.contentobject_id = x.obj_id AND ezlink.contentobject_state_id = {$params['object_state']}" : "";
1818

1919
$cacheDir = eZSys::cacheDirectory();
2020
$currentSiteAccessName = $GLOBALS['eZCurrentAccess']['name'];
@@ -27,25 +27,21 @@ static function citiesBySubtree( eZContentObjectTreeNode $node, $params )
2727
$cacheFile = eZClusterFileHandler::instance( $cacheFilePath );
2828
if ( !$cacheFile->exists() or ( time() - $cacheFile->mtime() > $cacheTime ) )
2929
{
30-
$list = $db->arrayQuery( "SELECT city, count(city) as 'count' FROM ezxgis_position AS gisp
31-
JOIN ezcontentobject_attribute AS ezatt
32-
ON gisp.contentobject_attribute_id = ezatt.id
33-
JOIN ezcontentobject as ezobj
34-
ON ezatt.contentobject_id = ezobj.id
35-
AND ezobj.current_version = gisp.contentobject_attribute_version
36-
JOIN ezcontentobject_tree as eztree
37-
ON ezobj.id = eztree.contentobject_id
38-
AND eztree.path_string LIKE '{$node->attribute('path_string')}%'
39-
AND eztree.is_hidden = 0
40-
AND eztree.is_invisible = 0
41-
{$subselect}
42-
WHERE city != ''
43-
GROUP BY city
44-
ORDER BY count desc", array('column' => 'city') );
30+
$list = $db->arrayQuery( "(SELECT city, count(city) as 'count' FROM ezxgis_position AS gisp,
31+
(SELECT ezatt.id AS obj_att_id, x.obj_id, x.obj_current_version FROM ezcontentobject_attribute AS ezatt,
32+
(SELECT ezobj.id AS obj_id, ezobj.current_version AS obj_current_version FROM ezcontentobject AS ezobj,
33+
(SELECT contentobject_id FROM ezcontentobject_tree AS eztree
34+
WHERE eztree.path_string LIKE '{$node->attribute('path_string')}%' AND eztree.is_hidden = 0 AND eztree.is_invisible = 0
35+
) AS z
36+
WHERE z.contentobject_id = ezobj.id
37+
) AS x
38+
{$subselect}
39+
WHERE ezatt.contentobject_id = x.obj_id
40+
) AS y
41+
WHERE city != '' AND gisp.contentobject_attribute_id = y.obj_att_id AND gisp.contentobject_attribute_version = y.obj_current_version
42+
GROUP BY city ORDER BY null) ORDER BY count desc", array('column' => 'city') );
4543
$cacheFile->storeContents( serialize( $list ), 'query_cache', 'json' );
46-
}
47-
else
48-
{
44+
} else {
4945
$list = unserialize( $cacheFile->fetchContents() );
5046
}
5147
return $list;

0 commit comments

Comments
 (0)