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);
}
// @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;
}
}