ENHANCEMENT: orderMoreSpecifically results are now cached for performance improvements

This commit is contained in:
Geoff Munn 2010-12-02 22:33:25 +00:00
parent 4d3cfcd58e
commit 667eac707f

View File

@ -79,6 +79,15 @@ class PostgreSQLDatabase extends SS_Database {
*/
private static $cached_constraints=array();
/**
*
* This holds a copy of all the queries that run through the function orderMoreSpecifically()
* It appears to be a performance bottleneck at times.
*
* @var array
*/
private static $cached_ordered_specifically=array();
/**
* Override the language that tsearch uses. By default it is 'english, but
* could be any of the supported languages that can be found in the
@ -1541,6 +1550,11 @@ class PostgreSQLDatabase extends SS_Database {
protected function orderMoreSpecifically($select,$order) {
//create a key so we can cache this result and quickly return it if we've done it before
$cache_key=serialize($select) . $order;
if(isset(self::$cached_ordered_specifically[$cache_key]))
return self::$cached_ordered_specifically[$cache_key];
$altered = false;
// split expression into order terms
@ -1565,7 +1579,11 @@ class PostgreSQLDatabase extends SS_Database {
}
}
return implode(',', $terms);
//Hold this result in the cache
$result=implode(',', $terms);
self::$cached_ordered_specifically[$cache_key]=$result;
return $result;
}
/*