Skip to content

Commit 9a0034a

Browse files
committed
Memoize custom sources' field layouts
#17484
1 parent 7475379 commit 9a0034a

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44

5+
- Improved the performance of element indexes when custom sources are defined. ([#17484](https://github.com/craftcms/cms/issues/17484))
56
- Fixed a bug where Matrix fields could load nested entries that belonged to other owner elements. ([#17551](https://github.com/craftcms/cms/issues/17551))
67
- Fixed a potential user account enumeration bug when `preventUserEnumeration` was enabled.
78

src/services/ElementSources.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -293,21 +293,21 @@ public function getTableAttributes(string $elementType, string $sourceKey, ?arra
293293
*/
294294
public function getFieldLayoutsForSource(string $elementType, string $sourceKey): array
295295
{
296-
// Don't bother the element type for custom sources
297-
if (str_starts_with($sourceKey, 'custom:')) {
298-
$source = $this->_sourceConfig($elementType, $sourceKey);
299-
if (empty($source['condition'])) {
300-
return Craft::$app->getFields()->getLayoutsByType($elementType);
301-
}
302-
/** @var ElementConditionInterface $condition */
303-
$condition = Craft::$app->getConditions()->createCondition($source['condition']);
304-
$query = $elementType::find();
305-
$condition->modifyQuery($query);
306-
return $query->getFieldLayouts();
307-
}
308-
309296
if (!isset($this->_fieldLayouts[$elementType][$sourceKey])) {
310-
$this->_fieldLayouts[$elementType][$sourceKey] = $elementType::fieldLayouts($sourceKey);
297+
// Don't bother the element type for custom sources
298+
if (str_starts_with($sourceKey, 'custom:')) {
299+
$source = $this->_sourceConfig($elementType, $sourceKey);
300+
if (empty($source['condition'])) {
301+
return Craft::$app->getFields()->getLayoutsByType($elementType);
302+
}
303+
/** @var ElementConditionInterface $condition */
304+
$condition = Craft::$app->getConditions()->createCondition($source['condition']);
305+
$query = $elementType::find();
306+
$condition->modifyQuery($query);
307+
$this->_fieldLayouts[$elementType][$sourceKey] = $query->getFieldLayouts();
308+
} else {
309+
$this->_fieldLayouts[$elementType][$sourceKey] = $elementType::fieldLayouts($sourceKey);
310+
}
311311
}
312312

313313
return $this->_fieldLayouts[$elementType][$sourceKey];

0 commit comments

Comments
 (0)