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

Ticket #4706 - Timeline: Update Hot feed generation formula.

AntonLV 2 лет назад
Родитель
Сommit
86bce5d09d

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

@@ -57,7 +57,8 @@
     <string name="_bx_timeline_option_hot_threshold_age"><![CDATA[Максимальный возраст поста, получившего комментарии/голоса, который включается в 'горячую' хронику (в днях, 0 - без ограничений)]]></string>
     <string name="_bx_timeline_option_hot_threshold_comment"><![CDATA[Минимальное количество комментариев, необходимое для появления контента в 'горячей' хронике]]></string>
     <string name="_bx_timeline_option_hot_threshold_vote"><![CDATA[Минимальное количество голосов, необходимое для появления контента в 'горячей' хронике]]></string>
-    <string name="_bx_timeline_option_hot_interval"><![CDATA[Интервал времени (в часах) для получения 'горячих' событий]]></string>
+    <string name="_bx_timeline_option_hot_interval"><![CDATA[Интервал времени (в часах) для получения 'горячих' событий (0 – без ограничений)]]></string>
+    <string name="_bx_timeline_option_hot_content_age_mux"><![CDATA[Коэффициент корректировки, связанный с возрастом контента (0 – без корректировки)]]></string>
     <string name="_bx_timeline_option_enable_cache_item"><![CDATA[Включить кэш элемента]]></string>
     <string name="_bx_timeline_option_cache_item_engine"><![CDATA[Механизм кэширования элемента (отличный от FileHtml может потребовать дополнительную настройку сервера)]]></string>
     <string name="_bx_timeline_option_cache_item_lifetime"><![CDATA[Время жизни кэша элемента]]></string>

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

@@ -55,6 +55,7 @@ class BxTimelineConfig extends BxBaseModNotificationsConfig
     protected $_iHotThresholdContent;
     protected $_iHotThresholdComment;
     protected $_iHotThresholdVote;
+    protected $_fHotContentAgeMux;
     protected $_aHotSources;
     protected $_aHotSourcesList;
     protected $_aHotList;
@@ -492,6 +493,7 @@ class BxTimelineConfig extends BxBaseModNotificationsConfig
         $this->_iHotThresholdComment = (int)getParam($sOptionPrefix . 'hot_threshold_comment');
         $this->_iHotThresholdVote = (int)getParam($sOptionPrefix . 'hot_threshold_vote');
         $this->_iHotInterval = (int)getParam($sOptionPrefix . 'hot_interval');
+        $this->_fHotContentAgeMux = (float)getParam($sOptionPrefix . 'hot_content_age_mux');
         $this->_aHotSources = explode(',', getParam($sOptionPrefix . 'hot_sources'));
         $this->_aHotList = $this->_bHot ? $this->_oDb->getHot() : [];
 
@@ -872,6 +874,11 @@ class BxTimelineConfig extends BxBaseModNotificationsConfig
         return $this->_iHotInterval;
     }
 
+    public function getHotContentAgeMux()
+    {
+        return $this->_fHotContentAgeMux;
+    }
+
     public function getLimitAttachLinks()
     {
         return $this->_iLimitAttachLinks;

+ 5 - 2
modules/boonex/timeline/classes/BxTimelineCronHot.php

@@ -119,8 +119,11 @@ class BxTimelineCronHot extends BxDolCron
         $aTracks = $this->_combineArrays($aTracks, $aTracksByDateComments);
         $aTracks = $this->_combineArrays($aTracks, $aTracksByDateVotes);
 
-        foreach($aTracks as $iId => $iDate)
-            $this->_oModule->_oDb->updateHotTrack(array('event_id' => $iId, 'value' => $iDate));
+        /*
+         * Currently $iValue contains event creation date.
+         */
+        foreach($aTracks as $iEventId => $iValue)
+            $this->_oModule->_oDb->updateHotTrack($iEventId, $iValue);
     }
 
     /**

+ 53 - 22
modules/boonex/timeline/classes/BxTimelineDb.php

@@ -425,29 +425,42 @@ class BxTimelineDb extends BxBaseModNotificationsDb
         return $this->query("TRUNCATE TABLE `" . $this->_sTableHotTrack . "`");
     }
 
-    public function getHotTrackByDate($iInterval = 24)
+    public function getHotTrackByDate($iInterval = 0)
     {
         $aBindings = [
-            'interval' => $iInterval
+            'mux' => $this->_oConfig->getHotContentAgeMux()
         ];
+        $sQueryWhere = "";
+
+        if($iInterval != 0) {
+            $aBindings['interval'] = $iInterval;
+
+            $sQueryWhere .= " AND `te`.`date` > (UNIX_TIMESTAMP() - 3600 * :interval)";
+        }
 
         $sQuery = "SELECT 
                 `te`.`id` AS `event_id`,
-                `te`.`date` AS `value`
+                `te`.`date` * (1 - :mux * (UNIX_TIMESTAMP() - `te`.`date`) / UNIX_TIMESTAMP()) AS `value`
             FROM `" . $this->_sTable . "` AS `te`
-            WHERE (`te`.`system` <> 0 OR `te`.`owner_id` = 0) AND `te`.`date` > (UNIX_TIMESTAMP() - 3600 * :interval)";
+            WHERE (`te`.`system` <> 0 OR `te`.`owner_id` = 0)" . $sQueryWhere;
 
         return $this->getPairs($sQuery, 'event_id', 'value', $aBindings);
     }
 
-    public function getHotTrackByCommentsDate($sModule, $sTableTrack, $iInterval = 24, $iThresholdAge = 0, $iThresholdCount = 0)
+    public function getHotTrackByCommentsDate($sModule, $sTableTrack, $iInterval = 0, $iThresholdAge = 0, $iThresholdCount = 0)
     {
         $aBindings = [
+            'mux' => $this->_oConfig->getHotContentAgeMux(),
             'module' => $sModule, 
-            'interval' => $iInterval
         ];
 
-        $sQueryWhere = " AND (`te`.`system` <> 0 OR `te`.`owner_id` = 0) AND `tt`.`cmt_time` > (UNIX_TIMESTAMP() - 3600 * :interval)";
+        $sQueryWhere = " AND (`te`.`system` <> 0 OR `te`.`owner_id` = 0)";
+        
+        if($iInterval != 0) {
+            $aBindings['interval'] = $iInterval;
+            
+            $sQueryWhere .= " AND `tt`.`cmt_time` > (UNIX_TIMESTAMP() - 3600 * :interval)";
+        }
 
         if($iThresholdAge != 0) {
             $aBindings['threshold_age'] = $iThresholdAge;
@@ -464,7 +477,7 @@ class BxTimelineDb extends BxBaseModNotificationsDb
 
         $sQuery = "SELECT 
                 `te`.`id` as `event_id`,
-                MAX(`tt`.`cmt_time`) AS `value`
+                MAX(`tt`.`cmt_time`) * (1 - :mux * (UNIX_TIMESTAMP() - `te`.`date`) / UNIX_TIMESTAMP()) AS `value`
             FROM `" . $this->_sTable . "` AS `te`
             INNER JOIN `" . $sTableTrack . "` AS `tt` ON `te`.`id`=`tt`.`cmt_object_id` AND `te`.`object_owner_id`<>`tt`.`cmt_author_id` AND `te`.`type`=:module 
             WHERE 1 " . $sQueryWhere . " 
@@ -473,14 +486,19 @@ class BxTimelineDb extends BxBaseModNotificationsDb
         return $this->getPairs($sQuery, 'event_id', 'value', $aBindings);
     }
 
-    public function getHotTrackByCommentsDateModule($sModule, $sTableTrack, $iInterval = 24, $iThresholdAge = 0, $iThresholdCount = 0)
+    public function getHotTrackByCommentsDateModule($sModule, $sTableTrack, $iInterval = 0, $iThresholdAge = 0, $iThresholdCount = 0)
     {
         $aBindings = [
+            'mux' => $this->_oConfig->getHotContentAgeMux(),
             'module' => $sModule, 
-            'interval' => $iInterval
         ];
 
-        $sQueryWhere = " AND (`te`.`system` <> 0 OR `te`.`owner_id` = 0) AND `tt`.`cmt_time` > (UNIX_TIMESTAMP() - 3600 * :interval)";
+        $sQueryWhere = " AND (`te`.`system` <> 0 OR `te`.`owner_id` = 0)";
+        if($iInterval != 0) {
+            $aBindings['interval'] = $iInterval;
+            
+            $sQueryWhere .= " AND `tt`.`cmt_time` > (UNIX_TIMESTAMP() - 3600 * :interval)";
+        }
 
         if($iThresholdAge != 0) {
             $aBindings['threshold_age'] = $iThresholdAge;
@@ -497,7 +515,7 @@ class BxTimelineDb extends BxBaseModNotificationsDb
 
         $sQuery = "SELECT 
                 `te`.`id` as `event_id`,
-                MAX(`tt`.`cmt_time`) AS `value`
+                MAX(`tt`.`cmt_time`) * (1 - :mux * (UNIX_TIMESTAMP() - `te`.`date`) / UNIX_TIMESTAMP()) AS `value`
             FROM `" . $this->_sTable . "` AS `te`
             INNER JOIN `" . $sTableTrack . "` AS `tt` ON `te`.`object_id`=`tt`.`cmt_object_id` AND `te`.`object_owner_id`<>`tt`.`cmt_author_id` AND `te`.`type`=:module
             WHERE 1 " . $sQueryWhere . " 
@@ -506,14 +524,19 @@ class BxTimelineDb extends BxBaseModNotificationsDb
         return $this->getPairs($sQuery, 'event_id', 'value', $aBindings);
     }
 
-    public function getHotTrackByVotesDate($sModule, $sTableTrack, $iInterval = 24, $iThresholdAge = 0, $iThresholdCount = 0)
+    public function getHotTrackByVotesDate($sModule, $sTableTrack, $iInterval = 0, $iThresholdAge = 0, $iThresholdCount = 0)
     {
         $aBindings = [
+            'mux' => $this->_oConfig->getHotContentAgeMux(),
             'module' => $sModule, 
-            'interval' => $iInterval
         ];
 
-        $sQueryWhere = " AND (`te`.`system` <> 0 OR `te`.`owner_id` = 0) AND `tt`.`date` > (UNIX_TIMESTAMP() - 3600 * :interval)";
+        $sQueryWhere = " AND (`te`.`system` <> 0 OR `te`.`owner_id` = 0)";
+        if($iInterval != 0) {
+            $aBindings['interval'] = $iInterval;
+
+            $sQueryWhere .= " AND `tt`.`date` > (UNIX_TIMESTAMP() - 3600 * :interval)";
+        }
 
         if($iThresholdAge != 0) {
             $aBindings['threshold_age'] = $iThresholdAge;
@@ -530,7 +553,7 @@ class BxTimelineDb extends BxBaseModNotificationsDb
 
         $sQuery = "SELECT 
                 `te`.`id` as `event_id`,
-                MAX(`tt`.`date`) AS `value`
+                MAX(`tt`.`date`) * (1 - :mux * (UNIX_TIMESTAMP() - `te`.`date`) / UNIX_TIMESTAMP()) AS `value`
             FROM `" . $this->_sTable . "` AS `te`
             INNER JOIN `" . $sTableTrack . "` AS `tt` ON `te`.`id`=`tt`.`object_id` AND `te`.`object_owner_id`<>`tt`.`author_id` AND `te`.`type`=:module 
             WHERE 1 " . $sQueryWhere . " 
@@ -539,14 +562,19 @@ class BxTimelineDb extends BxBaseModNotificationsDb
         return $this->getPairs($sQuery, 'event_id', 'value', $aBindings);
     }
 
-    public function getHotTrackByVotesDateModule($sModule, $sTableTrack, $iInterval = 24, $iThresholdAge = 0, $iThresholdCount = 0)
+    public function getHotTrackByVotesDateModule($sModule, $sTableTrack, $iInterval = 0, $iThresholdAge = 0, $iThresholdCount = 0)
     {
         $aBindings = [
+            'mux' => $this->_oConfig->getHotContentAgeMux(),
             'module' => $sModule, 
-            'interval' => $iInterval
         ];
 
-        $sQueryWhere = " AND (`te`.`system` <> 0 OR `te`.`owner_id` = 0) AND `tt`.`date` > (UNIX_TIMESTAMP() - 3600 * :interval)";
+        $sQueryWhere = " AND (`te`.`system` <> 0 OR `te`.`owner_id` = 0)";
+        if($iInterval != 0) {
+            $aBindings['interval'] = $iInterval;
+
+            $sQueryWhere .= " AND `tt`.`date` > (UNIX_TIMESTAMP() - 3600 * :interval)";
+        }
 
         if($iThresholdAge != 0) {
             $aBindings['threshold_age'] = $iThresholdAge;
@@ -563,7 +591,7 @@ class BxTimelineDb extends BxBaseModNotificationsDb
 
         $sQuery = "SELECT 
                 `te`.`id` as `event_id`,
-                MAX(`tt`.`date`) AS `value`
+                MAX(`tt`.`date`) * (1 - :mux * (UNIX_TIMESTAMP() - `te`.`date`) / UNIX_TIMESTAMP()) AS `value`
             FROM `" . $this->_sTable . "` AS `te`
             INNER JOIN `" . $sTableTrack . "` AS `tt` ON `te`.`object_id`=`tt`.`object_id` AND `te`.`object_owner_id`<>`tt`.`author_id` AND `te`.`type`=:module 
             WHERE 1 " . $sQueryWhere . " 
@@ -604,9 +632,12 @@ class BxTimelineDb extends BxBaseModNotificationsDb
         return $this->getAll($sQuery, array('module' => $sModule, 'interval' => $iInterval));
     }
 
-    public function updateHotTrack($aTrack)
+    public function updateHotTrack($iEventId, $iValue)
     {
-        return (int)$this->query("REPLACE INTO `" . $this->_sTableHotTrack . "` SET " . $this->arrayToSQL($aTrack)) > 0;
+        return (int)$this->query("INSERT INTO `" . $this->_sTableHotTrack . "` (`event_id`, `value`) VALUES (:event_id, :value) ON DUPLICATE KEY UPDATE `value` = :value", [
+            'event_id' => $iEventId,
+            'value' => $iValue
+        ]) > 0;
     }
 
     public function rebuildSlice()

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

@@ -57,7 +57,8 @@
     <string name="_bx_timeline_option_hot_threshold_age"><![CDATA[Maximum age of commented/voted post that gets included in Hot feed (in days, 0 - no limit)]]></string>
     <string name="_bx_timeline_option_hot_threshold_comment"><![CDATA[Minimum number of comments for content to appear in Hot feed]]></string>
     <string name="_bx_timeline_option_hot_threshold_vote"><![CDATA[Minimum number of votes for content to appear in Hot feed]]></string>
-    <string name="_bx_timeline_option_hot_interval"><![CDATA[Interval of time (in hours) to get Hot events]]></string>
+    <string name="_bx_timeline_option_hot_interval"><![CDATA[Interval of time (in hours) to get Hot events (0 - no limit)]]></string>
+    <string name="_bx_timeline_option_hot_content_age_mux"><![CDATA[Adjustment coefficient  related  to content age (0 - no adjustment)]]></string>
     <string name="_bx_timeline_option_enable_cache_item"><![CDATA[Enable item cache]]></string>
     <string name="_bx_timeline_option_cache_item_engine"><![CDATA[Item cache engine (other than File option may require custom server setup)]]></string>
     <string name="_bx_timeline_option_cache_item_lifetime"><![CDATA[Item cache lifetime]]></string>

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

@@ -389,7 +389,8 @@ INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `c
 ('bx_timeline_hot_threshold_age', '0', @iCategId, '_bx_timeline_option_hot_threshold_age', 'digit', '', '', '', '', 11),
 ('bx_timeline_hot_threshold_comment', '1', @iCategId, '_bx_timeline_option_hot_threshold_comment', 'digit', '', '', '', '', 12),
 ('bx_timeline_hot_threshold_vote', '2', @iCategId, '_bx_timeline_option_hot_threshold_vote', 'digit', '', '', '', '', 13),
-('bx_timeline_hot_interval', '48', @iCategId, '_bx_timeline_option_hot_interval', 'digit', '', '', '', '', 20);
+('bx_timeline_hot_interval', '48', @iCategId, '_bx_timeline_option_hot_interval', 'digit', '', '', '', '', 20),
+('bx_timeline_hot_content_age_mux', '0', @iCategId, '_bx_timeline_option_hot_content_age_mux', 'digit', '', '', '', '', 30);
 
 INSERT INTO `sys_options_categories` (`type_id`, `name`, `caption`, `order`)
 VALUES (@iTypeId, 'bx_timeline_feed_for_you', '_bx_timeline_options_category_feed_for_you', 7);