mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 12:00:55 +01:00
Reduce the cost of loading large numbers of macros
Summary: Ref T6013. I accidentally made this cost explosviely huge when fixing macros for logged out users in D10411. Specifically, we'd load all the macros, which would load all the files, which would load all the macros (to do policy checks), which would fill out of cache I think (but maybe only some of the time?). Anyway, bad news. Instead, only load the files if we need them. Test Plan: Viewed macro main page, macro detail, used a macro, used a meme, edited a macro, edited audio. Reviewers: btrahan, csilvers Reviewed By: csilvers Subscribers: epriestley, spicyj Maniphest Tasks: T6013 Differential Revision: https://secure.phabricator.com/D10428
This commit is contained in:
parent
ac4247ea59
commit
b772a2b92a
6 changed files with 29 additions and 15 deletions
|
@ -30,8 +30,9 @@ final class MacroQueryConduitAPIMethod extends MacroConduitAPIMethod {
|
|||
}
|
||||
|
||||
protected function execute(ConduitAPIRequest $request) {
|
||||
$query = new PhabricatorMacroQuery();
|
||||
$query->setViewer($request->getUser());
|
||||
$query = id(new PhabricatorMacroQuery())
|
||||
->setViewer($request->getUser())
|
||||
->needFiles(true);
|
||||
|
||||
$author_phids = $request->getValue('authorPHIDs');
|
||||
$phids = $request->getValue('phids');
|
||||
|
|
|
@ -19,6 +19,7 @@ final class PhabricatorMacroEditController extends PhabricatorMacroController {
|
|||
$macro = id(new PhabricatorMacroQuery())
|
||||
->setViewer($user)
|
||||
->withIDs(array($this->id))
|
||||
->needFiles(true)
|
||||
->executeOne();
|
||||
if (!$macro) {
|
||||
return new Aphront404Response();
|
||||
|
|
|
@ -29,6 +29,7 @@ final class PhabricatorMacroMemeController
|
|||
$macro = id(new PhabricatorMacroQuery())
|
||||
->setViewer($user)
|
||||
->withNames(array($macro_name))
|
||||
->needFiles(true)
|
||||
->executeOne();
|
||||
if (!$macro) {
|
||||
return false;
|
||||
|
|
|
@ -20,6 +20,7 @@ final class PhabricatorMacroViewController
|
|||
$macro = id(new PhabricatorMacroQuery())
|
||||
->setViewer($user)
|
||||
->withIDs(array($this->id))
|
||||
->needFiles(true)
|
||||
->executeOne();
|
||||
if (!$macro) {
|
||||
return new Aphront404Response();
|
||||
|
|
|
@ -12,6 +12,8 @@ final class PhabricatorMacroQuery
|
|||
private $dateCreatedBefore;
|
||||
private $flagColor;
|
||||
|
||||
private $needFiles;
|
||||
|
||||
private $status = 'status-any';
|
||||
const STATUS_ANY = 'status-any';
|
||||
const STATUS_ACTIVE = 'status-active';
|
||||
|
@ -83,6 +85,11 @@ final class PhabricatorMacroQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function needFiles($need_files) {
|
||||
$this->needFiles = $need_files;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function loadPage() {
|
||||
$macro_table = new PhabricatorFileImageMacro();
|
||||
$conn = $macro_table->establishConnection('r');
|
||||
|
@ -196,21 +203,23 @@ final class PhabricatorMacroQuery
|
|||
}
|
||||
|
||||
protected function didFilterPage(array $macros) {
|
||||
$file_phids = mpull($macros, 'getFilePHID');
|
||||
$files = id(new PhabricatorFileQuery())
|
||||
->setViewer($this->getViewer())
|
||||
->setParentQuery($this)
|
||||
->withPHIDs($file_phids)
|
||||
->execute();
|
||||
$files = mpull($files, null, 'getPHID');
|
||||
if ($this->needFiles) {
|
||||
$file_phids = mpull($macros, 'getFilePHID');
|
||||
$files = id(new PhabricatorFileQuery())
|
||||
->setViewer($this->getViewer())
|
||||
->setParentQuery($this)
|
||||
->withPHIDs($file_phids)
|
||||
->execute();
|
||||
$files = mpull($files, null, 'getPHID');
|
||||
|
||||
foreach ($macros as $key => $macro) {
|
||||
$file = idx($files, $macro->getFilePHID());
|
||||
if (!$file) {
|
||||
unset($macros[$key]);
|
||||
continue;
|
||||
foreach ($macros as $key => $macro) {
|
||||
$file = idx($files, $macro->getFilePHID());
|
||||
if (!$file) {
|
||||
unset($macros[$key]);
|
||||
continue;
|
||||
}
|
||||
$macro->attachFile($file);
|
||||
}
|
||||
$macro->attachFile($file);
|
||||
}
|
||||
|
||||
return $macros;
|
||||
|
|
|
@ -29,6 +29,7 @@ final class PhabricatorMacroSearchEngine
|
|||
|
||||
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||||
$query = id(new PhabricatorMacroQuery())
|
||||
->needFiles(true)
|
||||
->withIDs($saved->getParameter('ids', array()))
|
||||
->withPHIDs($saved->getParameter('phids', array()))
|
||||
->withAuthorPHIDs($saved->getParameter('authorPHIDs', array()));
|
||||
|
|
Loading…
Reference in a new issue