Skip to content

Commit

Permalink
ENH Cache DataObject::getSchema()
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jun 27, 2023
1 parent 0c40cc9 commit 46d7930
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/ORM/DataObject.php
Expand Up @@ -329,14 +329,25 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
*/
private static $cascade_duplicates = [];

/**
* Used to cache the schema to prevent repeatedly fetching the singleton
* While this is a fast operation, in some scenarios getSchema() is called an extremely large number of times
*
* @internal
*/
private static ?DataObjectSchema $schema = null;

/**
* Get schema object
*
* @return DataObjectSchema
*/
public static function getSchema()
{
return Injector::inst()->get(DataObjectSchema::class);
if (is_null(self::$schema)) {
self::$schema = Injector::inst()->get(DataObjectSchema::class);
}
return self::$schema;
}

/**
Expand Down

0 comments on commit 46d7930

Please sign in to comment.