1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 22:10: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:
epriestley 2014-09-05 17:30:26 -07:00
parent ac4247ea59
commit b772a2b92a
6 changed files with 29 additions and 15 deletions

View file

@ -30,8 +30,9 @@ final class MacroQueryConduitAPIMethod extends MacroConduitAPIMethod {
} }
protected function execute(ConduitAPIRequest $request) { protected function execute(ConduitAPIRequest $request) {
$query = new PhabricatorMacroQuery(); $query = id(new PhabricatorMacroQuery())
$query->setViewer($request->getUser()); ->setViewer($request->getUser())
->needFiles(true);
$author_phids = $request->getValue('authorPHIDs'); $author_phids = $request->getValue('authorPHIDs');
$phids = $request->getValue('phids'); $phids = $request->getValue('phids');

View file

@ -19,6 +19,7 @@ final class PhabricatorMacroEditController extends PhabricatorMacroController {
$macro = id(new PhabricatorMacroQuery()) $macro = id(new PhabricatorMacroQuery())
->setViewer($user) ->setViewer($user)
->withIDs(array($this->id)) ->withIDs(array($this->id))
->needFiles(true)
->executeOne(); ->executeOne();
if (!$macro) { if (!$macro) {
return new Aphront404Response(); return new Aphront404Response();

View file

@ -29,6 +29,7 @@ final class PhabricatorMacroMemeController
$macro = id(new PhabricatorMacroQuery()) $macro = id(new PhabricatorMacroQuery())
->setViewer($user) ->setViewer($user)
->withNames(array($macro_name)) ->withNames(array($macro_name))
->needFiles(true)
->executeOne(); ->executeOne();
if (!$macro) { if (!$macro) {
return false; return false;

View file

@ -20,6 +20,7 @@ final class PhabricatorMacroViewController
$macro = id(new PhabricatorMacroQuery()) $macro = id(new PhabricatorMacroQuery())
->setViewer($user) ->setViewer($user)
->withIDs(array($this->id)) ->withIDs(array($this->id))
->needFiles(true)
->executeOne(); ->executeOne();
if (!$macro) { if (!$macro) {
return new Aphront404Response(); return new Aphront404Response();

View file

@ -12,6 +12,8 @@ final class PhabricatorMacroQuery
private $dateCreatedBefore; private $dateCreatedBefore;
private $flagColor; private $flagColor;
private $needFiles;
private $status = 'status-any'; private $status = 'status-any';
const STATUS_ANY = 'status-any'; const STATUS_ANY = 'status-any';
const STATUS_ACTIVE = 'status-active'; const STATUS_ACTIVE = 'status-active';
@ -83,6 +85,11 @@ final class PhabricatorMacroQuery
return $this; return $this;
} }
public function needFiles($need_files) {
$this->needFiles = $need_files;
return $this;
}
protected function loadPage() { protected function loadPage() {
$macro_table = new PhabricatorFileImageMacro(); $macro_table = new PhabricatorFileImageMacro();
$conn = $macro_table->establishConnection('r'); $conn = $macro_table->establishConnection('r');
@ -196,6 +203,7 @@ final class PhabricatorMacroQuery
} }
protected function didFilterPage(array $macros) { protected function didFilterPage(array $macros) {
if ($this->needFiles) {
$file_phids = mpull($macros, 'getFilePHID'); $file_phids = mpull($macros, 'getFilePHID');
$files = id(new PhabricatorFileQuery()) $files = id(new PhabricatorFileQuery())
->setViewer($this->getViewer()) ->setViewer($this->getViewer())
@ -212,6 +220,7 @@ final class PhabricatorMacroQuery
} }
$macro->attachFile($file); $macro->attachFile($file);
} }
}
return $macros; return $macros;
} }

View file

@ -29,6 +29,7 @@ final class PhabricatorMacroSearchEngine
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
$query = id(new PhabricatorMacroQuery()) $query = id(new PhabricatorMacroQuery())
->needFiles(true)
->withIDs($saved->getParameter('ids', array())) ->withIDs($saved->getParameter('ids', array()))
->withPHIDs($saved->getParameter('phids', array())) ->withPHIDs($saved->getParameter('phids', array()))
->withAuthorPHIDs($saved->getParameter('authorPHIDs', array())); ->withAuthorPHIDs($saved->getParameter('authorPHIDs', array()));