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

Ticket #4367 - Timeline optimization: Point 2.

AntonLV 3 лет назад
Родитель
Сommit
6345f50ab8

+ 9 - 16
modules/base/notifications/classes/BxBaseModNotificationsDb.php

@@ -471,24 +471,17 @@ class BxBaseModNotificationsDb extends BxBaseModGeneralDb
                 break;
 
             case 'first':
-                    $sMethod = 'getRow';
-                    list($sJoinClause, $sWhereClause) = $this->_getSqlPartsEventsList($aParams);
-                    $sOrderClause = "ORDER BY `{$this->_sTable}`.`date` DESC, `{$this->_sTable}`.`id` DESC";
-                    $sLimitClause = "LIMIT 1";
-                    break;
-
-            case 'last':
-                    $sMethod = 'getRow';
-                    list($sJoinClause, $sWhereClause) = $this->_getSqlPartsEventsList($aParams);
-                    $sOrderClause = "ORDER BY `{$this->_sTable}`.`date` ASC, `{$this->_sTable}`.`id` ASC";
-                    $sLimitClause = "LIMIT 1";
-                    break;
+                $sMethod = 'getRow';
+                list($sJoinClause, $sWhereClause) = $this->_getSqlPartsEventsList($aParams);
+                $sOrderClause = "ORDER BY `{$this->_sTable}`.`date` DESC, `{$this->_sTable}`.`id` DESC";
+                $sLimitClause = "LIMIT 1";
+                break;
 
             case 'list':
-                    list($sJoinClause, $sWhereClause) = $this->_getSqlPartsEventsList($aParams);
-                    $sOrderClause = "ORDER BY `{$this->_sTable}`.`date` DESC, `{$this->_sTable}`.`id` DESC";
-                    $sLimitClause = isset($aParams['per_page']) ? "LIMIT " . $aParams['start'] . ", " . $aParams['per_page'] : "";
-                    break;
+                list($sJoinClause, $sWhereClause) = $this->_getSqlPartsEventsList($aParams);
+                $sOrderClause = "ORDER BY `{$this->_sTable}`.`date` DESC, `{$this->_sTable}`.`id` DESC";
+                $sLimitClause = isset($aParams['per_page']) ? "LIMIT " . $aParams['start'] . ", " . $aParams['per_page'] : "";
+                break;
         }
 
         return array($sMethod, $sSelectClause, $sJoinClause, $sWhereClause, $sOrderClause, $sLimitClause);

+ 8 - 1
modules/boonex/timeline/classes/BxTimelineDb.php

@@ -742,6 +742,14 @@ class BxTimelineDb extends BxBaseModNotificationsDb
                     $sWhereClause .= "AND `{$this->_sTable}`.`content` LIKE " . $this->escape('%' . $aParams['action'] . '%');
                 break;
 
+            case 'last':
+                $sMethod = 'getRow';
+                $sSelectClause .= ", YEAR(FROM_UNIXTIME(`{$this->_sTable}`.`date`)) AS `year`";
+                list($sJoinClause, $sWhereClause) = $this->_getSqlPartsEventsList($aParams);
+                $sOrderClause = "ORDER BY `{$this->_sTable}`.`date` ASC, `{$this->_sTable}`.`id` ASC";
+                $sLimitClause = "LIMIT 1";
+                break;
+
             case 'list':
                 list($sMethod, $sSelectClause, $sJoinClause, $sWhereClause, $sOrderClause, $sLimitClause) = parent::_getSqlPartsEvents($aParams);
                 if(in_array($aParams['type'], array(BX_TIMELINE_TYPE_CHANNELS, BX_TIMELINE_TYPE_FEED, BX_BASE_MOD_NTFS_TYPE_CONNECTIONS, BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS)))
@@ -756,7 +764,6 @@ class BxTimelineDb extends BxBaseModNotificationsDb
             	list($sMethod, $sSelectClause, $sJoinClause, $sWhereClause, $sOrderClause, $sLimitClause) = parent::_getSqlPartsEvents($aParams);
         }
 
-        $sSelectClause .= ", DAYOFYEAR(FROM_UNIXTIME(`{$this->_sTable}`.`date`)) AS `days`, DAYOFYEAR(NOW()) AS `today`, ROUND((UNIX_TIMESTAMP() - `{$this->_sTable}`.`date`)/86400) AS `ago_days`, YEAR(FROM_UNIXTIME(`{$this->_sTable}`.`date`)) AS `year`";
         if($this->_isList($aParams)) {
             $sOrderClause = "";
 

+ 0 - 68
modules/boonex/timeline/classes/BxTimelineTemplate.php

@@ -24,15 +24,12 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
     protected static $_sTmplContentTypePost;
     protected static $_sTmplContentTypeRepost;
 
-    protected $_bShowTimelineDividers;
     protected $_aAclId2Name;
 
     function __construct(&$oConfig, &$oDb)
     {
         parent::__construct($oConfig, $oDb);
 
-        $this->_bShowTimelineDividers = false;
-
         $this->_aAclId2Name = array();
 
         bx_import('BxTemplAcl');
@@ -761,26 +758,10 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
 
         $aParamsDb = $aParams;
 
-        //--- Before: Check for Previous
-        $iDays = -1;
-        $bPrevious = false;
-        if($iStart - 1 >= 0) {
-            $aParamsDb['start'] -= 1;
-            $aParamsDb['per_page'] += 1;
-            $bPrevious = true;
-        }
-
         //--- Before: Check for Next
         $aParamsDb['per_page'] += 1;
         $aEvents = $this->_oDb->getEvents($aParamsDb);
 
-        //--- After: Check for Previous
-        if($bPrevious) {
-            $aEvent = array_shift($aEvents);
-            if ($aEvent)
-                $iDays = (int)$aEvent['days'];
-        }
-
         //--- After: Check for Next
         $bNext = false;
         if(count($aEvents) > $iPerPage) {
@@ -795,8 +776,6 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
         $iEvents = count($aEvents);
         if($iEvents > 0)
             $iFirst = $this->_getFirst($aEvents, $aParams);
-        else 
-            $sContent .= $bViewTimeline ? $this->getDividerToday() : '';
 
         //--- Check for Visual Grouping
         $aGroups = array();
@@ -839,7 +818,6 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
 
         $iExtenalsEvery = $this->_oConfig->getExtenalsEvery($aParams['type']);
 
-        $bFirst = true;
         $iEventIndex = 0;
         $mixedEvents = $bReturnArray ? array() : '';
         foreach($aEvents as $aEvent) {
@@ -854,13 +832,6 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
                 continue;
             }
 
-            if($bFirst && $bViewTimeline) {
-                $mixedEvents .= $this->getDividerToday($aEvent);
-
-                $bFirst = false;
-            }
-
-            $mixedEvents .= $bViewTimeline ? $this->getDivider($iDays, $aEvent) : '';
             $mixedEvents .= $sEvent;
 
             $iEventIndex++;
@@ -906,45 +877,6 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
         ));
     }
 
-    public function getDivider(&$iDays, &$aEvent)
-    {
-        if(!$this->_bShowTimelineDividers || $iDays == $aEvent['days'])
-            return '';
-
-        $iDays = $aEvent['days'];
-        $iDaysAgo = (int)$aEvent['ago_days'];
-        if($aEvent['today'] == $aEvent['days'] || (($aEvent['today'] - $aEvent['days']) == 1 && $iDaysAgo == 0))
-            return '';
-
-        return $this->parseHtmlByName('divider.html', array(
-        	'style_prefix' => $this->_oConfig->getPrefix('style'),
-            'type' => 'common',
-            'bx_if:show_hidden' => array(
-                'condition' => false,
-                'content' => array()
-            ),
-            'content' => bx_time_js($aEvent['date'])
-        ));
-    }
-
-    public function getDividerToday($aEvent = array())
-    {
-        if(!$this->_bShowTimelineDividers)
-            return '';
-
-    	$bToday = !empty($aEvent) && ($aEvent['today'] == $aEvent['days'] || (($aEvent['today'] - $aEvent['days']) == 1 && (int)$aEvent['ago_days'] == 0));
-
-        return $this->parseHtmlByName('divider.html', array(
-        	'style_prefix' => $this->_oConfig->getPrefix('style'),
-            'type' => 'today',
-        	'bx_if:show_hidden' => array(
-                'condition' => !$bToday,
-                'content' => array()
-            ),
-            'content' => _t('_bx_timeline_txt_today')
-        ));
-    }
-
     public function getSizer($aParams)
     {
         if($aParams['view'] != BX_TIMELINE_VIEW_OUTLINE)