Просмотр исходного кода

Ticket #4367 - Timeline optimization: Point 1 (Async Live Updates).

AntonLV 3 лет назад
Родитель
Сommit
47a7134a1e

+ 6 - 4
inc/classes/BxDolLiveUpdates.php

@@ -151,7 +151,7 @@ class BxDolLiveUpdates extends BxDolFactory implements iBxDolSingleton
     	return $aResult;
     }
 
-    protected function _addSystem($sName, $iFrequency, $sServiceCall, $bActive = true)
+    protected function _addSystem($sName, $iFrequency, $sServiceCall, $mixedActive = true)
     {
         if(!$this->_iProfileId)
             return false;
@@ -166,13 +166,15 @@ class BxDolLiveUpdates extends BxDolFactory implements iBxDolSingleton
             $this->_aSystemsActive[] = $sName;
 
         if(empty($this->_aSystems[$sName])) {
-            $this->_aSystems[$sName] = array(
+            list($bActive, $bInit) = is_array($mixedActive) ? $mixedActive : [$mixedActive, true];
+            
+            $this->_aSystems[$sName] = [
                 'name' => $sName,
-                'init' => 1,
+                'init' => $bInit ? 1 : 0,
                 'frequency' => $iFrequency,
                 'service_call' => $sServiceCall,
                 'active' => $bActive ? 1 : 0
-            );
+            ];
 
             $this->_updateCached('systems', $this->_aSystems);
         }

+ 1 - 0
modules/boonex/russian/data/langs/bx_timeline/ru.xml

@@ -25,6 +25,7 @@
     <string name="_bx_timeline_option_events_per_preload"><![CDATA[Бесконечная прокрутка: Количество элементов, получаемых при авто-подгрузке]]></string>
     <string name="_bx_timeline_option_auto_preloads"><![CDATA[Бесконечная прокрутка: Количество авто-подгрузок]]></string>
     <string name="_bx_timeline_option_rss_length"><![CDATA[Количество элементов в RSS-ленте]]></string>
+    <string name="_bx_timeline_option_live_updates_length"><![CDATA[Количество элементов в выборке авто обновления]]></string>
     <string name="_bx_timeline_option_events_hide"><![CDATA[Показывать события]]></string>
     <string name="_bx_timeline_option_enable_brief_cards"><![CDATA[Включить лаконичные карточки]]></string>
     <string name="_bx_timeline_option_title_chars"><![CDATA[Количество символов в автогенерируемом заголовке сообщения]]></string>

+ 2 - 2
modules/boonex/timeline/classes/BxTimelineConfig.php

@@ -415,11 +415,11 @@ class BxTimelineConfig extends BxBaseModNotificationsConfig
         $this->_bInfScroll = getParam($sOptionPrefix . 'enable_infinite_scroll') == 'on';
         $this->_iInfScrollAutoPreloads = (int)getParam($sOptionPrefix . 'auto_preloads');
 
-        $this->_iRssLength = (int)getParam($sOptionPrefix . 'rss_length');       
+        $this->_iRssLength = (int)getParam($sOptionPrefix . 'rss_length');
+        $this->_iLiveUpdateLength = (int)getParam($sOptionPrefix . 'live_updates_length');
 
         $this->_bBriefCards = getParam($sOptionPrefix . 'enable_brief_cards') == 'on';
 
-        $this->_iLiveUpdateLength = 10;
         $this->_iCharsDisplayMinTitle = (int)getParam($sOptionPrefix . 'title_chars_short');
         $this->_iCharsDisplayMaxTitle = (int)getParam($sOptionPrefix . 'title_chars');
 

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

@@ -3212,9 +3212,10 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
             return false;
 
         $aParams = $this->_prepareParams($aBrowseParams);
-        $aParams = array_merge($aParams, array(
+        $aParams = array_merge($aParams, [
+            'per_page' => $this->_oConfig->getLiveUpdateLength(),
             'filter' => BX_TIMELINE_FILTER_OTHER_VIEWER
-        ));
+        ]);
         $aEvents = $this->_oDb->getEvents($aParams);
         if(empty($aEvents) || !is_array($aEvents))
             return false;

+ 4 - 4
modules/boonex/timeline/classes/BxTimelineTemplate.php

@@ -381,18 +381,18 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
 
         $sModuleName = $oModule->getName();
         $sModuleMethod = !empty($aParams['get_live_updates']) ? $aParams['get_live_updates'] : 'get_live_update';
-        $sService = BxDolService::getSerializedService($sModuleName, $sModuleMethod, array($aParams, $oModule->getUserId(), '{count}', '{init}'));
+        $sService = BxDolService::getSerializedService($sModuleName, $sModuleMethod, [$aParams, $oModule->getUserId(), '{count}', '{init}']);
 
-        $aLiveUpdateParams = array($this->_oConfig->getLiveUpdateKey($aParams), 1, $sService, true);
+        $aLiveUpdateParams = [$this->_oConfig->getLiveUpdateKey($aParams), 1, $sService, [true, false]];
         if($sModuleMethod == 'get_live_update')
             $aLiveUpdateParams[] = $iEvent;
 
         $sLiveUpdateCode = null;
-        bx_alert($sModuleName, 'add_live_update', 0, 0, array(
+        bx_alert($sModuleName, 'add_live_update', 0, 0, [
             'browse_params' => $aParams,
             'live_update_params' => &$aLiveUpdateParams,
             'override_result' => &$sLiveUpdateCode,
-        ));
+        ]);
 
         if($sLiveUpdateCode === null && ($oLiveUpdates = BxDolLiveUpdates::getInstance()) !== false)
             $sLiveUpdateCode = call_user_func_array([$oLiveUpdates, 'add'], $aLiveUpdateParams);

+ 1 - 0
modules/boonex/timeline/install/langs/en.xml

@@ -25,6 +25,7 @@
     <string name="_bx_timeline_option_events_per_preload"><![CDATA[Infinite Scroll: Number of items per preload]]></string>
     <string name="_bx_timeline_option_auto_preloads"><![CDATA[Infinite Scroll: Number of auto preloads]]></string>
     <string name="_bx_timeline_option_rss_length"><![CDATA[The length of RSS feed]]></string>
+    <string name="_bx_timeline_option_live_updates_length"><![CDATA[The length of Live Updates selection]]></string>
     <string name="_bx_timeline_option_events_hide"><![CDATA[Show events]]></string>
     <string name="_bx_timeline_option_enable_brief_cards"><![CDATA[Enable brief cards]]></string>
     <string name="_bx_timeline_option_title_chars"><![CDATA[Number of characters in auto-generated update's title]]></string>

+ 1 - 0
modules/boonex/timeline/install/sql/enable.sql

@@ -310,6 +310,7 @@ INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `c
 ('bx_timeline_events_per_page_home', '24', @iCategId, '_bx_timeline_option_events_per_page_home', 'digit', '', '', '', '', 12),
 ('bx_timeline_events_per_page', '24', @iCategId, '_bx_timeline_option_events_per_page', 'digit', '', '', '', '', 13),
 ('bx_timeline_rss_length', '5', @iCategId, '_bx_timeline_option_rss_length', 'digit', '', '', '', '', 14),
+('bx_timeline_live_updates_length', '5', @iCategId, '_bx_timeline_option_live_updates_length', 'digit', '', '', '', '', 15),
 
 ('bx_timeline_enable_infinite_scroll', '', @iCategId, '_bx_timeline_option_enable_infinite_scroll', 'checkbox', '', '', '', '', 20),
 ('bx_timeline_events_per_preload', '5', @iCategId, '_bx_timeline_option_events_per_preload', 'digit', '', '', '', '', 21),