Commit bf3d1874 authored by catch's avatar catch
Browse files

Issue #3548313 by ericpoir, klausi, liam morland, dmitry.korhov, rick...

Issue #3548313 by ericpoir, klausi, liam morland, dmitry.korhov, rick bergmann, pwolanin, alexpott: Updating to 10.5.3 causes gateway timeouts on revisioned content

(cherry picked from commit cb8784b6)
parent ad75505b
Loading
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -131,13 +131,15 @@ protected function prepare() {
      $this->sqlFields["base_table.$id_field"] = ['base_table', $id_field];
    }

    // Use max and group by to only return the latest revision in the most
    // optimal way.
    // Use a subquery with MAX() to only return the latest revision in the most
    // optimal way. Note that this query is extremely performance-sensitive and
    // changes here need to be tested on a database where there are many
    // revisions and many entities.
    if ($this->latestRevision && $revision_field) {
      // Fetch all latest revision ids in a sub-query.
      $revision_subquery = $this->connection->select($base_table, 'base_table');
      $revision_subquery->addExpression("MAX(base_table.$revision_field)");
      $revision_subquery->groupBy("base_table.$id_field");
      $revision_subquery = $this->connection->select($base_table, 'subquery_base_table');
      $revision_subquery->addExpression("MAX(subquery_base_table.$revision_field)");
      $revision_subquery->where("base_table.$id_field = subquery_base_table.$id_field");

      // Restrict results only to latest ids.
      $this->sqlQuery->condition("base_table.$revision_field", $revision_subquery, 'IN');