mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-19 05:12:41 +01:00
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
This commit is contained in:
parent
118c696f72
commit
417056932e
1 changed files with 20 additions and 10 deletions
|
@ -102,6 +102,8 @@ final class PhabricatorRepositoryDiscoveryEngine
|
|||
'Discovering commits in repository %s.',
|
||||
$repository->getCallsign()));
|
||||
|
||||
$this->fillCommitCache(array_values($branches));
|
||||
|
||||
$refs = array();
|
||||
foreach ($branches as $name => $commit) {
|
||||
$this->log(pht('Examining branch "%s", at "%s".', $name, $commit));
|
||||
|
@ -354,6 +356,8 @@ final class PhabricatorRepositoryDiscoveryEngine
|
|||
->setRepository($repository)
|
||||
->execute();
|
||||
|
||||
$this->fillCommitCache(mpull($branches, 'getCommitIdentifier'));
|
||||
|
||||
$refs = array();
|
||||
foreach ($branches as $branch) {
|
||||
// NOTE: Mercurial branches may have multiple heads, so the names may
|
||||
|
@ -473,24 +477,30 @@ final class PhabricatorRepositoryDiscoveryEngine
|
|||
return false;
|
||||
}
|
||||
|
||||
$commit = id(new PhabricatorRepositoryCommit())->loadOneWhere(
|
||||
'repositoryID = %d AND commitIdentifier = %s',
|
||||
$this->getRepository()->getID(),
|
||||
$identifier);
|
||||
$this->fillCommitCache(array($identifier));
|
||||
|
||||
if (!$commit) {
|
||||
return false;
|
||||
return isset($this->commitCache[$identifier]);
|
||||
}
|
||||
|
||||
private function fillCommitCache(array $identifiers) {
|
||||
if (!$identifiers) {
|
||||
return;
|
||||
}
|
||||
|
||||
$commits = id(new PhabricatorRepositoryCommit())->loadAllWhere(
|
||||
'repositoryID = %d AND commitIdentifier IN (%Ls)',
|
||||
$this->getRepository()->getID(),
|
||||
$identifiers);
|
||||
|
||||
foreach ($commits as $commit) {
|
||||
$this->commitCache[$commit->getCommitIdentifier()] = true;
|
||||
}
|
||||
|
||||
$this->commitCache[$identifier] = true;
|
||||
while (count($this->commitCache) > self::MAX_COMMIT_CACHE_SIZE) {
|
||||
array_shift($this->commitCache);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sort branches so we process closeable branches first. This makes the
|
||||
* whole import process a little cheaper, since we can close these commits
|
||||
|
|
Loading…
Reference in a new issue