mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 22:10:55 +01:00
Cache README content for repositories
Summary: Ref T11954. Especially with higher-latency file stores like S3, we can spend a lot of time reading README data and then pulling it out of file storage. Instead, cache it. Test Plan: Browsed a repostory with a README, saw faster pages. Reviewers: chad Reviewed By: chad Maniphest Tasks: T11954 Differential Revision: https://secure.phabricator.com/D17002
This commit is contained in:
parent
e6ddd6d0e9
commit
b869e742b9
1 changed files with 45 additions and 26 deletions
|
@ -340,41 +340,60 @@ abstract class DiffusionController extends PhabricatorController {
|
||||||
|
|
||||||
$drequest = $this->getDiffusionRequest();
|
$drequest = $this->getDiffusionRequest();
|
||||||
$viewer = $this->getViewer();
|
$viewer = $this->getViewer();
|
||||||
|
$repository = $drequest->getRepository();
|
||||||
|
$repository_phid = $repository->getPHID();
|
||||||
|
$stable_commit = $drequest->getStableCommit();
|
||||||
|
|
||||||
try {
|
$cache = PhabricatorCaches::getMutableStructureCache();
|
||||||
$result = $this->callConduitWithDiffusionRequest(
|
$cache_key = "diffusion".
|
||||||
'diffusion.filecontentquery',
|
".repository({$repository_phid})".
|
||||||
array(
|
".commit({$stable_commit})".
|
||||||
'path' => $readme_path,
|
".readme({$readme_path})";
|
||||||
'commit' => $drequest->getStableCommit(),
|
|
||||||
));
|
$readme_cache = $cache->getKey($cache_key);
|
||||||
} catch (Exception $ex) {
|
if (!$readme_cache) {
|
||||||
return null;
|
try {
|
||||||
|
$result = $this->callConduitWithDiffusionRequest(
|
||||||
|
'diffusion.filecontentquery',
|
||||||
|
array(
|
||||||
|
'path' => $readme_path,
|
||||||
|
'commit' => $drequest->getStableCommit(),
|
||||||
|
));
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$file_phid = $result['filePHID'];
|
||||||
|
if (!$file_phid) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$file = id(new PhabricatorFileQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->withPHIDs(array($file_phid))
|
||||||
|
->executeOne();
|
||||||
|
if (!$file) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$corpus = $file->loadFileData();
|
||||||
|
|
||||||
|
$readme_cache = array(
|
||||||
|
'corpus' => $corpus,
|
||||||
|
);
|
||||||
|
|
||||||
|
$cache->setKey($cache_key, $readme_cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
$file_phid = $result['filePHID'];
|
$readme_corpus = $readme_cache['corpus'];
|
||||||
if (!$file_phid) {
|
if (!strlen($readme_corpus)) {
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$file = id(new PhabricatorFileQuery())
|
|
||||||
->setViewer($viewer)
|
|
||||||
->withPHIDs(array($file_phid))
|
|
||||||
->executeOne();
|
|
||||||
if (!$file) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$corpus = $file->loadFileData();
|
|
||||||
|
|
||||||
if (!strlen($corpus)) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return id(new DiffusionReadmeView())
|
return id(new DiffusionReadmeView())
|
||||||
->setUser($this->getViewer())
|
->setUser($this->getViewer())
|
||||||
->setPath($readme_path)
|
->setPath($readme_path)
|
||||||
->setContent($corpus);
|
->setContent($readme_corpus);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue