Skip to content
Snippets Groups Projects
Commit 1b52a128 authored by Jared Hancock's avatar Jared Hancock
Browse files

orm: Avoid fetching columns more than once

If a common model is used in more than one select_related model (user and
user__email), avoid fetching the columns for the user model more than once.
parent 52190686
No related branches found
No related tags found
No related merge requests found
......@@ -1668,7 +1668,7 @@ class MySqlCompiler extends SqlCompiler {
// Handle deferreds
if (isset($defer[$f]))
continue;
$fields[] = $rootAlias . '.' . $this->quote($f);
$fields[$rootAlias . '.' . $this->quote($f)] = true;
$theseFields[] = $f;
}
$fieldMap[] = array($theseFields, $model);
......@@ -1691,10 +1691,14 @@ class MySqlCompiler extends SqlCompiler {
// Handle deferreds
if (isset($defer[$sr . '__' . $f]))
continue;
$fields[] = $alias . '.' . $this->quote($f);
elseif (isset($fields[$alias.'.'.$this->quote($f)]))
continue;
$fields[$alias . '.' . $this->quote($f)] = true;
$theseFields[] = $f;
}
$fieldMap[] = array($theseFields, $fmodel, $parts);
if ($theseFields) {
$fieldMap[] = array($theseFields, $fmodel, $parts);
}
$full_path .= '__';
}
}
......@@ -1704,9 +1708,9 @@ class MySqlCompiler extends SqlCompiler {
foreach ($queryset->values as $v) {
list($f) = $this->getField($v, $model);
if ($f instanceof SqlFunction)
$fields[] = $f->toSql($this, $model);
$fields[$f->toSql($this, $model)] = true;
else
$fields[] = $f;
$fields[$f] = true;
}
}
// Simple selection from one table
......@@ -1716,13 +1720,14 @@ class MySqlCompiler extends SqlCompiler {
foreach ($model::$meta['fields'] as $f) {
if (isset($queryset->defer[$f]))
continue;
$fields[] = $rootAlias .'.'. $this->quote($f);
$fields[$rootAlias .'.'. $this->quote($f)] = true;
}
}
else {
$fields[] = $rootAlias.'.*';
$fields[$rootAlias.'.*'] = true;
}
}
$fields = array_keys($fields);
// Add in annotations
if ($queryset->annotations) {
foreach ($queryset->annotations as $A) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment