[Memcached_DataObject] Check if it is possible to sort efficiently
This commit is contained in:
parent
25f67a1ce9
commit
ad6955e7ff
|
@ -102,6 +102,27 @@ class Memcached_DataObject extends Safe_DataObject
|
|||
$keyVals[$key] = $obj->escape($val);
|
||||
}
|
||||
|
||||
// Check if values are ordered, makes sorting in SQL easier
|
||||
$prev_val = reset($keyVals);
|
||||
$order_asc = $order_desc = true;
|
||||
foreach ($keyVals as $val) {
|
||||
if ($val < $prev_val) {
|
||||
$order_asc = false;
|
||||
}
|
||||
if ($val > $prev_val) {
|
||||
$order_desc = false;
|
||||
}
|
||||
if ($order_asc === false && $order_desc === false) {
|
||||
break;
|
||||
}
|
||||
$prev_val = $val;
|
||||
}
|
||||
|
||||
if ($order_asc) {
|
||||
$obj->orderBy($keyCol);
|
||||
} elseif ($order_desc) {
|
||||
$obj->orderBy("{$keyCol} DESC");
|
||||
} else {
|
||||
switch (common_config('db', 'type')) {
|
||||
case 'pgsql':
|
||||
// "position" will make sure we keep the desired order
|
||||
|
@ -122,6 +143,7 @@ class Memcached_DataObject extends Safe_DataObject
|
|||
default:
|
||||
throw new ServerException('Unknown DB type selected.');
|
||||
}
|
||||
}
|
||||
|
||||
$obj->find();
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user