From 2e96565f675d794ab485ec89ac73ce627c144730 Mon Sep 17 00:00:00 2001 From: elynde Date: Fri, 29 Apr 2011 17:10:52 -0700 Subject: [PATCH] Faster 'All Revisions and Reviews' Query Summary: The 'All Revisions and Reviews' Query takes about 2 seconds when I run it from the mysql command-line: SELECT revision.* FROM `differential_revision` revision LEFT JOIN `differential_relationship` relationship ON revision.id = relationship.revisionID AND relationship.relation = 'revw' WHERE revision.authorPHID in ('PHID-USER-a113b9ae4ee9524d0a20') OR relationship.objectPHID in ('PHID-USER-a113b9ae4ee9524d0a20') GROUP BY revision.id ORDER BY dateModified DESC 2419 rows in set (2.05 sec) This takes about 0.1-0.2 seconds. Just dug into this because I guess phabricator is haven't a bunch of mysql timeouts. I don't know what the hell I'm doing; this is just faster Test Plan: Loaded 'All Revisions and Reviews' in sandbox http://phabricator.dev1577.snc6.facebook.com/differential/filter/related/ Made sure it had same results as the version in prod https://phabricator.fb.com/differential/filter/related/ Still slow to generate all that html Reviewed By: epriestley Reviewers: epriestley, aran, tuomaspelkonen, jungejason CC: aran, epriestley Differential Revision: 182 --- .../DifferentialRevisionListData.php | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/applications/differential/data/revisionlist/DifferentialRevisionListData.php b/src/applications/differential/data/revisionlist/DifferentialRevisionListData.php index afa81d7c2f..fe50b86d11 100644 --- a/src/applications/differential/data/revisionlist/DifferentialRevisionListData.php +++ b/src/applications/differential/data/revisionlist/DifferentialRevisionListData.php @@ -90,10 +90,33 @@ class DifferentialRevisionListData { $this->ids); break; case self::QUERY_OWNED_OR_REVIEWER: - $this->revisions = $this->loadAllWhereJoinReview( - 'revision.authorPHID in (%Ls) OR relationship.objectPHID in (%Ls)', + $rev = new DifferentialRevision(); + $data = queryfx_all( + $rev->establishConnection('r'), + 'SELECT revs.* FROM ( + ( + SELECT revision.* + FROM %T revision + WHERE revision.authorPHID in (%Ls) + ) + UNION + ( + SELECT revision.* + FROM %T revision, %T rel + WHERE rel.revisionId = revision.Id + AND rel.relation = %s + AND rel.objectPHID in (%Ls) + ) + ) as revs + %Q', + $rev->getTableName(), $this->ids, - $this->ids); + $rev->getTableName(), + DifferentialRevision::RELATIONSHIP_TABLE, + DifferentialRevision::RELATION_REVIEWER, + $this->ids, + $this->getOrderClause()); + $this->revisions = $rev->loadAllFromArray($data); break; case self::QUERY_NEED_ACTION_FROM_SELF: $rev = new DifferentialRevision();