]> git.mxchange.org Git - friendica.git/commitdiff
Use activitites and remove unused config
authorMichael <heluecht@pirati.ca>
Sat, 2 Sep 2023 13:56:54 +0000 (13:56 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 2 Sep 2023 13:56:54 +0000 (13:56 +0000)
src/Module/Conversation/Channel.php
static/defaults.config.php

index 230a9ee8ae7d86d43a805284918b6d8fae43b3de..42ca508be52787d019d6c70495504d008fe82f7b 100644 (file)
@@ -238,17 +238,17 @@ class Channel extends BaseModule
        {
                if (self::$content == self::WHATSHOT) {
                        if (!is_null(self::$accountType)) {
-                               $condition = ["`comments` >= ? AND `contact-type` = ?", self::getMedianComments(4), self::$accountType];
+                               $condition = ["(`comments` >= ? OR `activities` >= ?) AND `contact-type` = ?", self::getMedianComments(4), self::getMedianActivities(4), self::$accountType];
                        } else {
-                               $condition = ["`comments` >= ? AND `contact-type` != ?", self::getMedianComments(4), Contact::TYPE_COMMUNITY];
+                               $condition = ["(`comments` >= ? OR `activities` >= ?) AND `contact-type` != ?", self::getMedianComments(4), self::getMedianActivities(4), Contact::TYPE_COMMUNITY];
                        }
                } elseif (self::$content == self::FORYOU) {
                        $cid = Contact::getPublicIdByUserId(DI::userSession()->getLocalUserId());
 
                        $condition = ["(`author-id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `thread-score` > ?) OR
-                               (`comments` >= ? AND `author-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` IN (?, ?))) OR
+                               ((`comments` >= ?  OR `activities` >= ?) AND `author-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` IN (?, ?))) OR
                                ( `author-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` IN (?, ?) AND `notify_new_posts`)))",
-                               $cid, self::getMedianThreadScore($cid, 4), self::getMedianComments(3), DI::userSession()->getLocalUserId(), Contact::FRIEND, Contact::SHARING,
+                               $cid, self::getMedianThreadScore($cid, 4), self::getMedianComments(4), self::getMedianActivities(4), DI::userSession()->getLocalUserId(), Contact::FRIEND, Contact::SHARING,
                                DI::userSession()->getLocalUserId(), Contact::FRIEND, Contact::SHARING];
                } elseif (self::$content == self::FOLLOWERS) {
                        $condition = ["`author-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` = ?)", DI::userSession()->getLocalUserId(), Contact::FOLLOWER];
@@ -302,7 +302,7 @@ class Channel extends BaseModule
 
        private static function getMedianComments(int $divider): int
        {
-               $cache_key = 'Channel:getHotPostsItemLimit:' . $divider;
+               $cache_key = 'Channel:getMedianComments:' . $divider;
                $comments  = DI::cache()->get($cache_key);
                if (!empty($comments)) {
                        return $comments;
@@ -319,6 +319,25 @@ class Channel extends BaseModule
                return $comments;
        }
 
+       private static function getMedianActivities(int $divider): int
+       {
+               $cache_key  = 'Channel:getMedianActivities:' . $divider;
+               $activities = DI::cache()->get($cache_key);
+               if (!empty($activities)) {
+                       return $activities;
+               }
+
+               $limit      = DBA::count('post-engagement', ["`contact-type` != ? AND `activities` > ?", Contact::TYPE_COMMUNITY, 0]) / $divider;
+               $post       = DBA::selectToArray('post-engagement', ['activities'], ["`contact-type` != ?", Contact::TYPE_COMMUNITY, 0], ['order' => ['activities' => true], 'limit' => [$limit, 1]]);
+               $activities = $post[0]['activities'] ?? 0;
+               if (empty($activities)) {
+                       return 0;
+               }
+
+               DI::cache()->set($cache_key, $activities, Duration::HOUR);
+               return $activities;
+       }
+
        private static function getMedianThreadScore(int $cid, int $divider): int
        {
                $cache_key = 'Channel:getThreadScore:' . $cid . ':' . $divider;
index 82cf8e0bcd5787c328bde73b1b86ac49b694ab75..f73a3300a15f696d8b936458154b39df7857b8a3 100644 (file)
@@ -804,9 +804,5 @@ return [
                // engagement_hours (Integer)
                // Number of hours posts are held in the engagement table
                'engagement_hours' => 24,
-
-               // hot_posts_item_limit (Integer)
-               // Number of items that are displayed on the "what's hot" channel
-               'hot_posts_item_limit' => 100,
        ],
 ];