From: Michael Date: Fri, 8 Sep 2023 05:06:27 +0000 (+0000) Subject: Language specific median calculations / collection X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=bbb21a73ad7e39eb6ac658585f1f1b00d6f1e13b;p=friendica.git Language specific median calculations / collection --- diff --git a/src/Content/Conversation/Collection/Channels.php b/src/Content/Conversation/Collection/Channels.php new file mode 100644 index 0000000000..a523cc7b2b --- /dev/null +++ b/src/Content/Conversation/Collection/Channels.php @@ -0,0 +1,28 @@ +. + * + */ + +namespace Friendica\Content\Conversation\Collection; + +use Friendica\BaseCollection; + +class Channels extends BaseCollection +{ +} diff --git a/src/Module/Conversation/Channel.php b/src/Module/Conversation/Channel.php index 27f5f9cad4..ee233bf75f 100644 --- a/src/Module/Conversation/Channel.php +++ b/src/Module/Conversation/Channel.php @@ -272,11 +272,7 @@ class Channel extends Timeline $this->selectedTab = ChannelEntity::FORYOU; } -<<<<<<< HEAD if (!$this->channel->isTimeline($this->selectedTab) && !$this->userDefinedChannel->isTimeline($this->selectedTab, $this->session->getLocalUserId()) && !$this->community->isTimeline($this->selectedTab)) { -======= - if (!in_array(self::$content, [self::WHATSHOT, self::FORYOU, self::FOLLOWERS, self::SHARERSOFSHARERS, self::IMAGE, self::VIDEO, self::AUDIO, self::LANGUAGE])) { ->>>>>>> 0818b4d1b3 (Fixes the score calculation concerning the relation-cid / cid interaction) throw new HTTPException\BadRequestException($this->l10n->t('Channel not available.')); } @@ -339,11 +335,12 @@ class Channel extends Timeline } elseif (self::$content == self::SHARERSOFSHARERS) { $cid = Contact::getPublicIdByUserId($this->session->getLocalUserId()); + // @todo Suggest posts from contacts that are followed most by our followers $condition = [ "`owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `follows` AND `last-interaction` > ? AND `relation-cid` IN (SELECT `cid` FROM `contact-relation` WHERE `follows` AND `relation-cid` = ? AND `relation-thread-score` >= ?) AND NOT `cid` IN (SELECT `cid` FROM `contact-relation` WHERE `follows` AND `relation-cid` = ?))", - DateTimeFormat::utc('now - 90 day'), $cid, $this->getMedianRelationThreadScore($cid, 4), $cid + DateTimeFormat::utc('now - ' . $this->config->get('channel', 'sharer_interaction_days') .' day'), $cid, $this->getMedianRelationThreadScore($cid, 4), $cid ]; } elseif (self::$content == self::IMAGE) { $condition = ["`media-type` & ?", 1]; @@ -426,41 +423,49 @@ class Channel extends Timeline private function getMedianComments(int $divider): int { - $cache_key = 'Channel:getMedianComments:' . $divider; + $languages = $this->pConfig->get($this->session->getLocalUserId(), 'channel', 'languages', [User::getLanguageCode($this->session->getLocalUserId())]); + $cache_key = 'Channel:getMedianComments:' . $divider . ':' . implode(':', $languages); $comments = $this->cache->get($cache_key); if (!empty($comments)) { return $comments; } - $limit = $this->database->count('post-engagement', ["`contact-type` != ? AND `comments` > ?", Contact::TYPE_COMMUNITY, 0]) / $divider; - $post = $this->database->selectToArray('post-engagement', ['comments'], ["`contact-type` != ?", Contact::TYPE_COMMUNITY], ['order' => ['comments' => true], 'limit' => [$limit, 1]]); + $condition = ["`contact-type` != ? AND `comments` > ?", Contact::TYPE_COMMUNITY, 0]; + $condition = $this->addLanguageCondition($condition); + + $limit = $this->database->count('post-engagement', $condition) / $divider; + $post = $this->database->selectToArray('post-engagement', ['comments'], $condition, ['order' => ['comments' => true], 'limit' => [$limit, 1]]); $comments = $post[0]['comments'] ?? 0; if (empty($comments)) { return 0; } $this->cache->set($cache_key, $comments, Duration::HALF_HOUR); - $this->logger->debug('Calculated median comments', ['divider' => $divider, 'median' => $comments]); + $this->logger->debug('Calculated median comments', ['divider' => $divider, 'languages' => $languages, 'median' => $comments]); return $comments; } private function getMedianActivities(int $divider): int { - $cache_key = 'Channel:getMedianActivities:' . $divider; + $languages = $this->pConfig->get($this->session->getLocalUserId(), 'channel', 'languages', [User::getLanguageCode($this->session->getLocalUserId())]); + $cache_key = 'Channel:getMedianActivities:' . $divider . ':' . implode(':', $languages); $activities = $this->cache->get($cache_key); if (!empty($activities)) { return $activities; } - $limit = $this->database->count('post-engagement', ["`contact-type` != ? AND `activities` > ?", Contact::TYPE_COMMUNITY, 0]) / $divider; - $post = $this->database->selectToArray('post-engagement', ['activities'], ["`contact-type` != ?", Contact::TYPE_COMMUNITY], ['order' => ['activities' => true], 'limit' => [$limit, 1]]); + $condition = ["`contact-type` != ? AND `activities` > ?", Contact::TYPE_COMMUNITY, 0]; + $condition = $this->addLanguageCondition($condition); + + $limit = $this->database->count('post-engagement', $condition) / $divider; + $post = $this->database->selectToArray('post-engagement', ['activities'], $condition, ['order' => ['activities' => true], 'limit' => [$limit, 1]]); $activities = $post[0]['activities'] ?? 0; if (empty($activities)) { return 0; } $this->cache->set($cache_key, $activities, Duration::HALF_HOUR); - $this->logger->debug('Calculated median activities', ['divider' => $divider, 'median' => $activities]); + $this->logger->debug('Calculated median activities', ['divider' => $divider, 'languages' => $languages, 'median' => $activities]); return $activities; } @@ -472,8 +477,10 @@ class Channel extends Timeline return $score; } - $limit = $this->database->count('contact-relation', ["`relation-cid` = ? AND `relation-thread-score` > ?", $cid, 0]) / $divider; - $relation = $this->database->selectToArray('contact-relation', ['relation-thread-score'], ['relation-cid' => $cid], ['order' => ['relation-thread-score' => true], 'limit' => [$limit, 1]]); + $condition = ["`relation-cid` = ? AND `relation-thread-score` > ?", $cid, 0]; + + $limit = $this->database->count('contact-relation', $condition) / $divider; + $relation = $this->database->selectToArray('contact-relation', ['relation-thread-score'], $condition, ['order' => ['relation-thread-score' => true], 'limit' => [$limit, 1]]); $score = $relation[0]['relation-thread-score'] ?? 0; if (empty($score)) { return 0;