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:
@@ -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');
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
@@ -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,21 +203,23 @@ final class PhabricatorMacroQuery
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function didFilterPage(array $macros) {
|
protected function didFilterPage(array $macros) {
|
||||||
$file_phids = mpull($macros, 'getFilePHID');
|
if ($this->needFiles) {
|
||||||
$files = id(new PhabricatorFileQuery())
|
$file_phids = mpull($macros, 'getFilePHID');
|
||||||
->setViewer($this->getViewer())
|
$files = id(new PhabricatorFileQuery())
|
||||||
->setParentQuery($this)
|
->setViewer($this->getViewer())
|
||||||
->withPHIDs($file_phids)
|
->setParentQuery($this)
|
||||||
->execute();
|
->withPHIDs($file_phids)
|
||||||
$files = mpull($files, null, 'getPHID');
|
->execute();
|
||||||
|
$files = mpull($files, null, 'getPHID');
|
||||||
|
|
||||||
foreach ($macros as $key => $macro) {
|
foreach ($macros as $key => $macro) {
|
||||||
$file = idx($files, $macro->getFilePHID());
|
$file = idx($files, $macro->getFilePHID());
|
||||||
if (!$file) {
|
if (!$file) {
|
||||||
unset($macros[$key]);
|
unset($macros[$key]);
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
$macro->attachFile($file);
|
||||||
}
|
}
|
||||||
$macro->attachFile($file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $macros;
|
return $macros;
|
||||||
|
|||||||
@@ -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()));
|
||||||
|
|||||||
Reference in New Issue
Block a user