소스 검색

Ticket #2040 - Bug fixes.

AntonLV 7 년 전
부모
커밋
0d99d49d6a
2개의 변경된 파일과 62개의 추가작업 그리고 25개의 파일을 삭제
  1. 3 1
      modules/boonex/timeline/classes/BxTimelineModule.php
  2. 59 24
      modules/boonex/timeline/classes/BxTimelineTemplate.php

+ 3 - 1
modules/boonex/timeline/classes/BxTimelineModule.php

@@ -202,7 +202,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
         if(!$this->deleteEvent($aEvent))
             return echoJson(array('code' => 3));
 
-        $this->_oModule->_oDb->deleteCache(array('event_id' => $iId));
+        $this->_oDb->deleteCache(array('event_id' => $iId));
 
         echoJson(array(
             'code' => 0, 
@@ -2268,6 +2268,8 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
                 $oMetatags->metaAdd($iId, $sText);
             $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
 
+            $this->_oDb->deleteCache(array('event_id' => $iId));
+
             return array(
                 'id' => $iId
             );

+ 59 - 24
modules/boonex/timeline/classes/BxTimelineTemplate.php

@@ -1119,6 +1119,34 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
         return $this->_oDb->insertCache($aParamsSet);
     }
 
+    protected function _cacheEvents($aParams)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        $iPerPage = (int)$aParams['per_page'];
+        $aParamsCopy = $aParams;
+
+        $aIds = array();
+        while(count($aIds) < $iPerPage) {
+            $aEvents = $this->_oDb->getEvents($aParamsCopy);
+            if(empty($aEvents))
+                break;
+
+            foreach($aEvents as $aEvent) {
+                if($this->getPost($aEvent, $aParamsCopy) == '')
+                    continue;
+
+                $aIds[] = $aEvent[$CNF['FIELD_ID']];
+                if(count($aIds) == $iPerPage)
+                    break 2;
+            }
+
+            $aParamsCopy['start'] += $iPerPage;
+        }
+
+        return $aIds;
+    }
+            
     protected function _getCachedEvents($iProfileId, &$aParams)
     {
         return $this->_oDb->getCache(array(
@@ -1145,53 +1173,60 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
          * Get cached data and check it for relevance.
          */
         $aCache = $this->_getCachedEvents($iProfileId, $aParams);
-        if(is_array($aCache) && count($aCache) == $iPerPage) {
+        if(is_array($aCache) && !empty($aCache)) {
+            if(($iCache = count($aCache)) != $iPerPage) {
+                $aRecachedIds = $this->_cacheEvents($aParams);
+                if(is_array($aRecachedIds) && count($aRecachedIds) > $iCache)
+                    $aCache = $this->_getCachedEvents($iProfileId, $aParams);
+            }
+
+            $bFound = false;
             $bUpdated = false;
+
             $aCachedItem = current($aCache);
+            $aCachedIds = array_keys($aCache);
 
+            $aParamsCopy = $aParams;
             while(true) {
-                $aEvents = $this->_oDb->getEvents($aParams);
+                $aEvents = $this->_oDb->getEvents($aParamsCopy);
                 if(empty($aEvents))
                     break;
 
                 foreach($aEvents as $aEvent) {
-                    if($aEvent[$CNF['FIELD_ID']] == $aCachedItem['event_id'])
+                    if($aEvent[$CNF['FIELD_ID']] == $aCachedItem['event_id']) {
+                        $bFound = true;
                         break 2;
+                    }
 
-                    if($this->getPost($aEvent, $aParams) == '')
+                    if(!in_array($aEvent[$CNF['FIELD_ID']], $aCachedIds) && $this->getPost($aEvent, $aParamsCopy) == '')
                         continue;
 
                     $bUpdated = true;
                 }
+
+                $aParamsCopy['start'] += $iPerPage;
+            }
+
+            /**
+             * If cached event wasn't found in real events list, 
+             * then clear cache and start the process from the beginning.
+             */
+            if(!$bFound) {
+                $this->_oModule->_oDb->deleteCache(array('type' => $aParams['type'], 'profile_id' => $iProfileId));
+
+                return $this->_getPosts($aParams);
             }
 
             if($bUpdated)
-                $aCache = $this->_getCachedEvents($iProfileId, $aParams);
+                $aCachedIds = array_keys($this->_getCachedEvents($iProfileId, $aParams));
 
-            return $this->_oDb->getEvents(array('browse' => 'ids', 'type' => $aParams['type'], 'ids' => array_keys($aCache)));
+            return $this->_oDb->getEvents(array('browse' => 'ids', 'type' => $aParams['type'], 'ids' => $aCachedIds));
         }
 
         /*
          * Cache data.
          */
-        $aIds = array();
-        while(count($aIds) < $iPerPage) {
-            $aEvents = $this->_oDb->getEvents($aParams);
-            if(empty($aEvents))
-                break;
-
-            foreach($aEvents as $aEvent) {
-                if($this->getPost($aEvent, $aParams) == '')
-                    continue;
-
-                $aIds[] = $aEvent[$CNF['FIELD_ID']];
-                if(count($aIds) == $iPerPage)
-                    break 2;
-            }
-
-            $aParams['start'] += $aParams['per_page'];
-        }        
-
+        $aIds = $this->_cacheEvents($aParams);
         return $this->_oDb->getEvents(array('browse' => 'ids', 'type' => $aParams['type'], 'ids' => $aIds));
     }