Merge pull request #10841 from creative-commoners/pulls/5/optimise-get-schema

ENH Cache DataObject::getSchema()
This commit is contained in:
Guy Sartorelli 2023-06-28 15:08:53 +12:00 committed by GitHub
commit 60ca35c02d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -329,6 +329,14 @@ 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
*
@ -336,7 +344,10 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
*/
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;
}
/**