From 46d7930489d6f27f5dc3157530c0e8938050d843 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 28 Jun 2023 11:11:43 +1200 Subject: [PATCH] ENH Cache DataObject::getSchema() --- src/ORM/DataObject.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/ORM/DataObject.php b/src/ORM/DataObject.php index 25e8c345bb9..5a06c5c1c0b 100644 --- a/src/ORM/DataObject.php +++ b/src/ORM/DataObject.php @@ -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; } /**