mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge pull request #4108 from Turnerj/fix/many-many-extrafields-performance
Fix/Performance: Combine multiple queries into one for ManyManyList::getExtraData
This commit is contained in:
commit
71d766a8d8
@ -362,17 +362,21 @@ class ManyManyList extends RelationList {
|
||||
user_error('ComponentSet::getExtraData() passed a non-numeric child ID', E_USER_ERROR);
|
||||
}
|
||||
|
||||
// @todo Optimize into a single query instead of one per extra field
|
||||
if($this->extraFields) {
|
||||
$cleanExtraFields = array();
|
||||
foreach ($this->extraFields as $fieldName => $dbFieldSpec) {
|
||||
$query = new SQLQuery("\"{$fieldName}\"", "\"{$this->joinTable}\"");
|
||||
$cleanExtraFields[] = "\"{$fieldName}\"";
|
||||
}
|
||||
$query = new SQLQuery($cleanExtraFields, "\"{$this->joinTable}\"");
|
||||
if($filter = $this->foreignIDWriteFilter($this->getForeignID())) {
|
||||
$query->setWhere($filter);
|
||||
} else {
|
||||
user_error("Can't call ManyManyList::getExtraData() until a foreign ID is set", E_USER_WARNING);
|
||||
}
|
||||
$query->addWhere("\"{$this->localKey}\" = {$itemID}");
|
||||
$result[$fieldName] = $query->execute()->value();
|
||||
$queryResult = $query->execute()->current();
|
||||
foreach ($queryResult as $fieldName => $value) {
|
||||
$result[$fieldName] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user