@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Make discovery slightly cheaper in the common case

Summary:
Ref T4605. Before discovering branches, try to prefill the cache in bulk. For repositories with large numbers of branches, this allows us to issue dramatically fewer queries.

(Before D8780, this cache was usually held across discovery events, so being able to fill it cheaply was not as relevant.)

Test Plan: Ran discovery on Git, Mercurial and SVN repositories. Observed fewer queries for Git/Mercurial.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4605

Differential Revision: https://secure.phabricator.com/D8781

+19 -9
+19 -9
src/applications/repository/engine/PhabricatorRepositoryDiscoveryEngine.php
··· 102 102 'Discovering commits in repository %s.', 103 103 $repository->getCallsign())); 104 104 105 + $this->fillCommitCache(array_values($branches)); 106 + 105 107 $refs = array(); 106 108 foreach ($branches as $name => $commit) { 107 109 $this->log(pht('Examining branch "%s", at "%s".', $name, $commit)); ··· 354 356 ->setRepository($repository) 355 357 ->execute(); 356 358 359 + $this->fillCommitCache(mpull($branches, 'getCommitIdentifier')); 360 + 357 361 $refs = array(); 358 362 foreach ($branches as $branch) { 359 363 // NOTE: Mercurial branches may have multiple heads, so the names may ··· 473 477 return false; 474 478 } 475 479 476 - $commit = id(new PhabricatorRepositoryCommit())->loadOneWhere( 477 - 'repositoryID = %d AND commitIdentifier = %s', 480 + $this->fillCommitCache(array($identifier)); 481 + 482 + return isset($this->commitCache[$identifier]); 483 + } 484 + 485 + private function fillCommitCache(array $identifiers) { 486 + if (!$identifiers) { 487 + return; 488 + } 489 + 490 + $commits = id(new PhabricatorRepositoryCommit())->loadAllWhere( 491 + 'repositoryID = %d AND commitIdentifier IN (%Ls)', 478 492 $this->getRepository()->getID(), 479 - $identifier); 493 + $identifiers); 480 494 481 - if (!$commit) { 482 - return false; 495 + foreach ($commits as $commit) { 496 + $this->commitCache[$commit->getCommitIdentifier()] = true; 483 497 } 484 498 485 - $this->commitCache[$identifier] = true; 486 499 while (count($this->commitCache) > self::MAX_COMMIT_CACHE_SIZE) { 487 500 array_shift($this->commitCache); 488 501 } 489 - 490 - return true; 491 502 } 492 - 493 503 494 504 /** 495 505 * Sort branches so we process closeable branches first. This makes the