mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-23 03:59:25 +01:00
Fix PhabricatorBot macro cacheing
Summary: Previously, if there were no macros, we would ping conduit for a list of macros until we got something. Now we cache false when there are no results. T3045 Test Plan: Ensure the init doesn't call the ##macro.query## conduit method more than once during the PhabricatorBot's lifetime. Reviewers: epriestley Reviewed By: epriestley CC: aran Maniphest Tasks: T3045 Differential Revision: https://secure.phabricator.com/D6671
This commit is contained in:
parent
40cf765ca2
commit
61f0671e87
1 changed files with 8 additions and 5 deletions
|
@ -8,7 +8,7 @@ final class PhabricatorBotMacroHandler extends PhabricatorBotHandler {
|
|||
private $macros;
|
||||
private $regexp;
|
||||
|
||||
private $next = 0;
|
||||
private $next = 0;
|
||||
|
||||
private function init() {
|
||||
if ($this->macros === false) {
|
||||
|
@ -22,18 +22,21 @@ final class PhabricatorBotMacroHandler extends PhabricatorBotHandler {
|
|||
$macros = $this->getConduit()->callMethodSynchronous(
|
||||
'macro.query',
|
||||
array());
|
||||
// bail if we have no macros
|
||||
if (empty($macros)) {
|
||||
|
||||
// If we have no macros, cache `false` (meaning "no macros") and return
|
||||
// immediately.
|
||||
if (!$macros) {
|
||||
$this->macros = false;
|
||||
return false;
|
||||
}
|
||||
$this->macros = $macros;
|
||||
|
||||
$regexp = array();
|
||||
foreach ($this->macros as $macro_name => $macro) {
|
||||
foreach ($macros as $macro_name => $macro) {
|
||||
$regexp[] = preg_quote($macro_name, '/');
|
||||
}
|
||||
$regexp = '/('.implode('|', $regexp).')/';
|
||||
|
||||
$this->macros = $macros;
|
||||
$this->regexp = $regexp;
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Add table
Reference in a new issue