فهرست منبع

#5522 Agents: queries cache for alert agents

Aleksandr Trofimov 4 ماه پیش
والد
کامیت
1816dfc133
3فایلهای تغییر یافته به همراه14 افزوده شده و 3 حذف شده
  1. 9 1
      inc/classes/BxDolAI.php
  2. 2 2
      inc/classes/BxDolAIQuery.php
  3. 3 0
      studio/template/scripts/BxBaseStudioAgentsAgents.php

+ 9 - 1
inc/classes/BxDolAI.php

@@ -433,7 +433,15 @@ class BxDolAI extends BxDolFactory implements iBxDolSingleton
 
     public function getAgentsByAlertUnitAndAction($sUnit, $sAction)
     {
-        return $this->_oDb->getAgentsByAlertUnitAndAction($sUnit, $sAction);
+        $aAgents = [];
+        $a = $this->_oDb->getAgentsWithAlert();
+        foreach ($a as $r) {
+            $aAlert = explode(':', $r['alert']);
+            if (count($aAlert) == 2 && $aAlert[0] == $sUnit && $aAlert[1] == $sAction)
+                $aAgents[] = $r;
+        }
+
+        return $aAgents;
     }
 
     public function getAgentsByProfileId($iProfileId)

+ 2 - 2
inc/classes/BxDolAIQuery.php

@@ -891,9 +891,9 @@ class BxDolAIQuery extends BxDolDb
         return $oDb->query($sQuery, ['status' => $sStatus, 'id' => $iId]);
     }
 
-    public function getAgentsByAlertUnitAndAction($sUnit, $sAction, $bActiveOnly = true)
+    public function getAgentsWithAlert($bActiveOnly = true)
     {
-        return $this->getAll("SELECT * FROM `sys_agents_agents` WHERE `trigger` = 'alert' AND `alert` = :alert AND `active` = :active", ['alert' => $sUnit . ':' . $sAction, 'active' => $bActiveOnly ? 1 : 0]);
+        return $this->fromCache('sys_agents_with_alert', 'getAll', "SELECT * FROM `sys_agents_agents` WHERE `trigger` = 'alert' AND `active` = :active", ['active' => $bActiveOnly ? 1 : 0]);
     }
 
     public function getAgentsByProfileId($iProfileId, $bActiveOnly = true)

+ 3 - 0
studio/template/scripts/BxBaseStudioAgentsAgents.php

@@ -126,6 +126,7 @@ class BxBaseStudioAgentsAgents extends BxDolStudioAgentsAgents
             $bIsValid = true;
             if($bIsValid) {
                 if(($iId = $oForm->insert($aValsToAdd)) !== false) {
+                    $this->_oDb->cleanCache('sys_agents_with_alert');
                     $aRes = ['grid' => $this->getCode(false), 'blink' => $iId];
                 }
                 else
@@ -193,6 +194,7 @@ class BxBaseStudioAgentsAgents extends BxDolStudioAgentsAgents
             $bIsValid = true;
             if($bIsValid) {
                 if(($iId = $oForm->update($iId, $aValsToAdd)) !== false) {
+                    $this->_oDb->cleanCache('sys_agents_with_alert');
                     $aRes = ['grid' => $this->getCode(false), 'blink' => $iId];
                 }
                 else
@@ -250,6 +252,7 @@ class BxBaseStudioAgentsAgents extends BxDolStudioAgentsAgents
     protected function _delete ($mixedId)
     {
         $mixedResult = parent::_delete($mixedId);
+        $this->_oDb->cleanCache('sys_agents_with_alert');
         if($mixedResult) {
             // $this->_oDb->deleteAutomatorProviders(['automator_id' => (int)$mixedId]);
             // $this->_oDb->deleteAutomatorHelpers(['automator_id' => (int)$mixedId]);