Skip to content

Commit 8c7cde1

Browse files
ENH Reduce count queries for scaffolding SearchableDropdownField (#11823)
1 parent cbec793 commit 8c7cde1

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/ORM/DataObject.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2633,7 +2633,7 @@ public function scaffoldFormFieldForHasOne(
26332633
$labelField = $this->hasField('Title') ? 'Title' : 'Name';
26342634
$list = DataList::create(static::class);
26352635
$threshold = DBForeignKey::config()->get('dropdown_field_threshold');
2636-
$overThreshold = $threshold === 0 || $list->count() > $threshold;
2636+
$overThreshold = $threshold === 0 || $list->setUseCache(true)->count() > $threshold;
26372637
$field = SearchableDropdownField::create($fieldName, $fieldTitle, $list, $ownerRecord->{$relationName . 'ID'}, $labelField)
26382638
->setIsLazyLoaded($overThreshold);
26392639
if ($threshold > 0) {

src/Security/Member.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,8 +1491,11 @@ private function scaffoldFormFieldForManyRelation(string $relationName, ?string
14911491
$field = SearchableMultiDropdownField::create($relationName, $fieldTitle, $list);
14921492
// Use the same lazyload threshold has_one relations use
14931493
$threshold = DBForeignKey::config()->get('dropdown_field_threshold');
1494-
$overThreshold = $list->count() > $threshold;
1495-
$field->setIsLazyLoaded($overThreshold)->setLazyLoadLimit($threshold);
1494+
$overThreshold = $threshold === 0 || $list->setUseCache(true)->count() > $threshold;
1495+
$field->setIsLazyLoaded($overThreshold);
1496+
if ($threshold > 0) {
1497+
$field->setLazyLoadLimit($threshold);
1498+
}
14961499
return $field;
14971500
}
14981501

0 commit comments

Comments
 (0)