1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-28 09:42:41 +01:00
phorge-phorge/src/applications/macro/conduit/MacroQueryConduitAPIMethod.php
epriestley b772a2b92a 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
2014-09-05 17:30:26 -07:00

84 lines
1.8 KiB
PHP

<?php
final class MacroQueryConduitAPIMethod extends MacroConduitAPIMethod {
public function getAPIMethodName() {
return 'macro.query';
}
public function getMethodDescription() {
return 'Retrieve image macro information.';
}
public function defineParamTypes() {
return array(
'authorPHIDs' => 'optional list<phid>',
'phids' => 'optional list<phid>',
'ids' => 'optional list<id>',
'names' => 'optional list<string>',
'nameLike' => 'optional string',
);
}
public function defineReturnType() {
return 'list<dict>';
}
public function defineErrorTypes() {
return array(
);
}
protected function execute(ConduitAPIRequest $request) {
$query = id(new PhabricatorMacroQuery())
->setViewer($request->getUser())
->needFiles(true);
$author_phids = $request->getValue('authorPHIDs');
$phids = $request->getValue('phids');
$ids = $request->getValue('ids');
$name_like = $request->getValue('nameLike');
$names = $request->getValue('names');
if ($author_phids) {
$query->withAuthorPHIDs($author_phids);
}
if ($phids) {
$query->withPHIDs($phids);
}
if ($ids) {
$query->withIDs($ids);
}
if ($name_like) {
$query->withNameLike($name_like);
}
if ($names) {
$query->withNames($names);
}
$macros = $query->execute();
if (!$macros) {
return array();
}
$results = array();
foreach ($macros as $macro) {
$file = $macro->getFile();
$results[$macro->getName()] = array(
'uri' => $file->getBestURI(),
'phid' => $macro->getPHID(),
'authorPHID' => $file->getAuthorPHID(),
'dateCreated' => $file->getDateCreated(),
'filePHID' => $file->getPHID(),
);
}
return $results;
}
}