Combine extrafield information into one query

Replaces the SQL query per-extrafield to one where all the data is
requested.
This commit is contained in:
Turnerj 2015-04-26 18:32:02 +09:30
parent 6c069ce7d5
commit 485f4c3b18

View File

@ -362,17 +362,21 @@ class ManyManyList extends RelationList {
user_error('ComponentSet::getExtraData() passed a non-numeric child ID', E_USER_ERROR); 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) { if($this->extraFields) {
foreach($this->extraFields as $fieldName => $dbFieldSpec) { $cleanExtraFields = array();
$query = new SQLQuery("\"{$fieldName}\"", "\"{$this->joinTable}\""); foreach ($this->extraFields as $fieldName => $dbFieldSpec) {
if($filter = $this->foreignIDWriteFilter($this->getForeignID())) { $cleanExtraFields[] = "\"{$fieldName}\"";
$query->setWhere($filter); }
} else { $query = new SQLQuery($cleanExtraFields, "\"{$this->joinTable}\"");
user_error("Can't call ManyManyList::getExtraData() until a foreign ID is set", E_USER_WARNING); if($filter = $this->foreignIDWriteFilter($this->getForeignID())) {
} $query->setWhere($filter);
$query->addWhere("\"{$this->localKey}\" = {$itemID}"); } else {
$result[$fieldName] = $query->execute()->value(); user_error("Can't call ManyManyList::getExtraData() until a foreign ID is set", E_USER_WARNING);
}
$query->addWhere("\"{$this->localKey}\" = {$itemID}");
$queryResult = $query->execute()->current();
foreach ($queryResult as $fieldName => $value) {
$result[$fieldName] = $value;
} }
} }