2012-03-09 21:40:03 +01:00
|
|
|
<?php
|
|
|
|
|
Rename Conduit classes
Summary: Ref T5655. Rename Conduit classes and provide a `getAPIMethodName` method to declare the API method.
Test Plan:
```
> echo '{}' | arc --conduit-uri='http://phabricator.joshuaspence.com' call-conduit user.whoami
Waiting for JSON parameters on stdin...
{"error":null,"errorMessage":null,"response":{"phid":"PHID-USER-lioqffnwn6y475mu5ndb","userName":"josh","realName":"Joshua Spence","image":"http:\/\/phabricator.joshuaspence.com\/res\/1404425321T\/phabricator\/3eb28cd9\/rsrc\/image\/avatar.png","uri":"http:\/\/phabricator.joshuaspence.com\/p\/josh\/","roles":["admin","verified","approved","activated"]}}
```
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: epriestley, Korvin, hach-que
Maniphest Tasks: T5655
Differential Revision: https://secure.phabricator.com/D9991
2014-07-25 02:54:15 +02:00
|
|
|
final class MacroQueryConduitAPIMethod extends MacroConduitAPIMethod {
|
|
|
|
|
|
|
|
public function getAPIMethodName() {
|
|
|
|
return 'macro.query';
|
|
|
|
}
|
2012-03-09 21:40:03 +01:00
|
|
|
|
|
|
|
public function getMethodDescription() {
|
2014-06-09 20:36:49 +02:00
|
|
|
return 'Retrieve image macro information.';
|
2012-03-09 21:40:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function defineParamTypes() {
|
|
|
|
return array(
|
2013-03-26 22:29:03 +01:00
|
|
|
'authorPHIDs' => 'optional list<phid>',
|
|
|
|
'phids' => 'optional list<phid>',
|
|
|
|
'ids' => 'optional list<id>',
|
|
|
|
'names' => 'optional list<string>',
|
|
|
|
'nameLike' => 'optional string',
|
2012-03-09 21:40:03 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function defineReturnType() {
|
|
|
|
return 'list<dict>';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function defineErrorTypes() {
|
|
|
|
return array(
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(ConduitAPIRequest $request) {
|
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-06 02:30:26 +02:00
|
|
|
$query = id(new PhabricatorMacroQuery())
|
|
|
|
->setViewer($request->getUser())
|
|
|
|
->needFiles(true);
|
2013-03-26 22:29:03 +01:00
|
|
|
|
|
|
|
$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();
|
|
|
|
}
|
2012-03-09 21:40:03 +01:00
|
|
|
|
|
|
|
$results = array();
|
|
|
|
foreach ($macros as $macro) {
|
2013-03-26 22:29:03 +01:00
|
|
|
$file = $macro->getFile();
|
2012-03-09 21:40:03 +01:00
|
|
|
$results[$macro->getName()] = array(
|
2013-03-26 22:29:03 +01:00
|
|
|
'uri' => $file->getBestURI(),
|
|
|
|
'phid' => $macro->getPHID(),
|
|
|
|
'authorPHID' => $file->getAuthorPHID(),
|
2014-08-15 20:08:11 +02:00
|
|
|
'dateCreated' => $file->getDateCreated(),
|
|
|
|
'filePHID' => $file->getPHID(),
|
2012-03-09 21:40:03 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|