From 84fc8f0baf9faa41fb75f7ec649e53fa19f0f306 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 11 May 2014 08:46:41 -0700 Subject: [PATCH] Don't try to rebuild a repository graph cache bucket more than once per request Summary: Ref T2683. This is a small optimization, but it has low complexity: don't rebuild a bucket more than once in the same request, since it will almost always be the same. Bucket rebuilds are pretty cheap, but this saves a few queries. Test Plan: - After discovering (but before parsing) a commit, viewed its browse view. Verified that this patch causes us to perform only one bucket rebuild, and therefore reduces the number of queries we issue. - Parsed the commit and viewed the browse view again, got successful rebuild and then fills from cache. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T2683 Differential Revision: https://secure.phabricator.com/D9055 --- .../PhabricatorRepositoryGraphCache.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/applications/repository/graphcache/PhabricatorRepositoryGraphCache.php b/src/applications/repository/graphcache/PhabricatorRepositoryGraphCache.php index 432bde057c..5cebece394 100644 --- a/src/applications/repository/graphcache/PhabricatorRepositoryGraphCache.php +++ b/src/applications/repository/graphcache/PhabricatorRepositoryGraphCache.php @@ -55,6 +55,8 @@ */ final class PhabricatorRepositoryGraphCache { + private $rebuiltKeys = array(); + /* -( Querying the Graph Cache )------------------------------------------- */ @@ -282,6 +284,20 @@ final class PhabricatorRepositoryGraphCache { * @task cache */ private function rebuildBucket($bucket_key, array $current_data) { + + // First, check if we've already rebuilt this bucket. In some cases (like + // browsing a repository at some commit) it's common to issue many lookups + // against one commit. If that commit has been discovered but not yet + // fully imported, we'll repeatedly attempt to rebuild the bucket. If the + // first rebuild did not work, subsequent rebuilds are very unlikely to + // have any effect. We can just skip the rebuild in these cases. + + if (isset($this->rebuiltKeys[$bucket_key])) { + return $current_data; + } else { + $this->rebuiltKeys[$bucket_key] = true; + } + $bucket_min = ($bucket_key * $this->getBucketSize()); $bucket_max = ($bucket_min + $this->getBucketSize()) - 1;