Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH Speed up DataObject::get_by_id by checking if there is an ID at all #10163

Merged
merged 1 commit into from
Jan 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/ORM/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@
* static $api_access = true;
*
* function canView($member = false) {
* if(!$member) $member = Security::getCurrentUser();
* if (!$member) $member = Security::getCurrentUser();
* return $member->inGroup('Subscribers');
* }
* function canEdit($member = false) {
* if(!$member) $member = Security::getCurrentUser();
* if (!$member) $member = Security::getCurrentUser();
* return $member->inGroup('Editors');
* }
*
Expand Down Expand Up @@ -3051,7 +3051,7 @@ public function can($perm, $member = null, $context = [])
*
* <code>
* $extended = $this->extendedCan('canDoSomething', $member);
* if($extended !== null) return $extended;
* if ($extended !== null) return $extended;
* else return $normalValue;
* </code>
*
Expand Down Expand Up @@ -3481,14 +3481,17 @@ public static function reset()
* @param int|bool $idOrCache The id of the element, or cache if called on target class
* @param boolean $cache See {@link get_one()}
*
* @return static The element
* @return static|null The element
*/
public static function get_by_id($classOrID, $idOrCache = null, $cache = true)
{
// Shift arguments if passing id in first or second argument
list ($class, $id, $cached) = is_numeric($classOrID)
? [get_called_class(), $classOrID, isset($idOrCache) ? $idOrCache : $cache]
: [$classOrID, $idOrCache, $cache];
? [get_called_class(), (int) $classOrID, isset($idOrCache) ? $idOrCache : $cache]
: [$classOrID, (int) $idOrCache, $cache];
if ($id < 1) {
return null;
}

// Validate class
if ($class === self::class) {
Expand Down