From a097e8663dcc9c75e4cad1e2721e9c0e9c10cac1 Mon Sep 17 00:00:00 2001 From: Bob Olde Hampsink Date: Fri, 29 May 2015 11:36:30 +0200 Subject: [PATCH] Performance improvements that mirror improvements in upcoming/latest Craft update --- supertable/models/SuperTable_BlockModel.php | 36 +++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/supertable/models/SuperTable_BlockModel.php b/supertable/models/SuperTable_BlockModel.php index 347b2ea..0e0424e 100755 --- a/supertable/models/SuperTable_BlockModel.php +++ b/supertable/models/SuperTable_BlockModel.php @@ -3,6 +3,11 @@ class SuperTable_BlockModel extends BaseElementModel { + // Static + // ========================================================================= + + private static $_preloadedFields = array(); + // Properties // ========================================================================= @@ -105,6 +110,37 @@ protected function defineAttributes() 'sortOrder' => AttributeType::Number, )); } + + /** + * @inheritdoc + */ + protected function createContent() + { + $fieldId = $this->fieldId; + + if (!isset(self::$_preloadedFields[$fieldId])) + { + $blockTypes = craft()->superTable->getBlockTypesByFieldId($fieldId); + + if (count($blockTypes) > 1) + { + $contexts = array(); + + foreach ($blockTypes as $blockType) + { + $contexts[] = 'superTableBlockType:'.$blockType->id; + } + + // Preload them to save ourselves some DB queries, and discard + craft()->fields->getAllFields(null, $contexts); + } + + // Don't do this again for this field + self::$_preloadedFields[$fieldId] = true; + } + + return parent::createContent(); + } // Private Methods // =========================================================================