Browse Source

Ticket #4414 - Timeline: All instances of Item cache should be cleaned.

AntonLV 3 years ago
parent
commit
735f4f8ae1

+ 9 - 0
modules/boonex/timeline/classes/BxTimelineConfig.php

@@ -646,6 +646,15 @@ class BxTimelineConfig extends BxBaseModNotificationsConfig
         return $this->getPrefix('cache_item') . $iId . (bx_is_mobile() ? '_m' : '') . '_r' . bx_get_device_pixel_ratio() . (!empty($sPostfix) ? '_' . $sPostfix : '') . '_' . bx_site_hash() . '.php';
     }
 
+    public function getCacheItemKeys($iId, $sPostfix = '')
+    {
+        $aVariants = ['_r1', '_r2', '_m_r1', '_m_r2'];
+
+        return array_map(function($sValue) use ($iId, $sPostfix) {
+            return $this->getPrefix('cache_item') . $iId . $sValue . (!empty($sPostfix) ? '_' . $sPostfix : '') . '_' . bx_site_hash() . '.php';
+        }, $aVariants);
+    }
+
     public function getCacheHotKey()
     {
         return $this->getPrefix('cache_list_hot');

+ 11 - 4
modules/boonex/timeline/classes/BxTimelineModule.php

@@ -4658,8 +4658,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
         }
 
         //--- Delete item cache.
-        $sCacheItemKey = $this->_oConfig->getCacheItemKey($aEvent[$CNF['FIELD_ID']]);
-        $this->getCacheItemObject()->delData($sCacheItemKey);
+        $this->deleteCacheItem($aEvent[$CNF['FIELD_ID']]);
 
         //--- Rebuild cache table.
         $this->rebuildSlice();
@@ -4786,9 +4785,9 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
         }
         
         //--- Delete item cache.
-        $sCacheItemKey = $this->_oConfig->getCacheItemKey($aEvent[$CNF['FIELD_ID']]);
-        $this->getCacheItemObject()->delData($sCacheItemKey);
+        $this->deleteCacheItem($aEvent[$CNF['FIELD_ID']]);
 
+        //--- Rebuild cache table.
         $this->rebuildSlice();
 
         //--- Event -> Delete for Alerts Engine ---//
@@ -5075,6 +5074,14 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
         return $bResult;
     }
 
+    public function deleteCacheItem($iEventId)
+    {
+        $oCacheItem = $this->getCacheItemObject();
+        $aCacheKeys = $this->_oConfig->getCacheItemKeys($iEventId);
+        foreach($aCacheKeys as $sCacheKey)
+            $oCacheItem->delData($sCacheKey);
+    }
+
     public function rebuildSlice()
     {
         if(!$this->_oConfig->isCacheTable())

+ 2 - 3
modules/boonex/timeline/classes/BxTimelineResponse.php

@@ -125,13 +125,12 @@ class BxTimelineResponse extends BxBaseModNotificationsResponse
                 $this->_oModule->_oDb->updateEvent($aParamsSet, ['id' => $aEvent[$CNF['FIELD_ID']]]);
 
                 //--- Delete item cache.
-                $oCacheItem = $this->_oModule->getCacheItemObject();
-                $oCacheItem->delData($this->_oModule->_oConfig->getCacheItemKey($aEvent['id']));
+                $this->_oModule->deleteCacheItem($aEvent['id']);
 
                 //--- Delete item cache for repost.
                 $aReposts = $this->_oModule->_oDb->getReposts($aEvent[$CNF['FIELD_ID']]);
                 foreach($aReposts as $aRepost)
-                    $oCacheItem->delData($this->_oModule->_oConfig->getCacheItemKey($aRepost['event_id']));
+                    $this->_oModule->deleteCacheItem($aRepost['event_id']);
 
                 $this->_oModule->rebuildSlice();
                 break;