From 61f0671e8730ce6c8a7e6a954000d04ce58cfc39 Mon Sep 17 00:00:00 2001 From: Korvin Szanto Date: Sun, 4 Aug 2013 15:40:04 -0700 Subject: [PATCH] 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 --- .../bot/handler/PhabricatorBotMacroHandler.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/infrastructure/daemon/bot/handler/PhabricatorBotMacroHandler.php b/src/infrastructure/daemon/bot/handler/PhabricatorBotMacroHandler.php index 9b02e2965c..009982fb5b 100644 --- a/src/infrastructure/daemon/bot/handler/PhabricatorBotMacroHandler.php +++ b/src/infrastructure/daemon/bot/handler/PhabricatorBotMacroHandler.php @@ -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;