ENHANCEMENT Improved performance of DataObject::get_by_id() by setting order to "1" in the contained get_one() call

This commit is contained in:
Sam Minnee 2010-12-02 15:51:35 +13:00 committed by Ingo Schommer
parent 0920b0fcd9
commit 5755c27c30
2 changed files with 4 additions and 5 deletions

View File

@ -2963,13 +2963,12 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
public static function get_by_id($callerClass, $id, $cache = true) { public static function get_by_id($callerClass, $id, $cache = true) {
if(is_numeric($id)) { if(is_numeric($id)) {
if(is_subclass_of($callerClass, 'DataObject')) { if(is_subclass_of($callerClass, 'DataObject')) {
$tableClasses = ClassInfo::dataClassesFor($callerClass); $baseClass = ClassInfo::baseDataClass($callerClass);
$baseClass = array_shift($tableClasses); return DataObject::get_one($callerClass,"\"$baseClass\".\"ID\" = $id", $cache, 1);
return DataObject::get_one($callerClass,"\"$baseClass\".\"ID\" = $id", $cache);
// This simpler code will be used by non-DataObject classes that implement DataObjectInterface // This simpler code will be used by non-DataObject classes that implement DataObjectInterface
} else { } else {
return DataObject::get_one($callerClass,"\"ID\" = $id", $cache); return DataObject::get_one($callerClass,"\"ID\" = $id", $cache, 1);
} }
} else { } else {
user_error("DataObject::get_by_id passed a non-numeric ID #$id", E_USER_WARNING); user_error("DataObject::get_by_id passed a non-numeric ID #$id", E_USER_WARNING);

View File

@ -557,7 +557,7 @@ class Member extends DataObject {
static function currentUser() { static function currentUser() {
$id = Member::currentUserID(); $id = Member::currentUserID();
if($id) { if($id) {
return DataObject::get_one("Member", "\"Member\".\"ID\" = $id"); return DataObject::get_one("Member", "\"Member\".\"ID\" = $id", true, 1);
} }
} }