mirror of
https://github.com/friendica/friendica
synced 2025-04-24 07:50:11 +00:00
New channel "quiet sharers" for posts from lesser frequent posters (#13913)
This commit is contained in:
parent
c6160a1c38
commit
f12276eff8
6 changed files with 77 additions and 36 deletions
|
@ -345,6 +345,13 @@ class Timeline extends BaseModule
|
|||
AND NOT `cid` IN (SELECT `cid` FROM `contact-relation` WHERE `follows` AND `relation-cid` = ?))",
|
||||
DateTimeFormat::utc('now - ' . $this->config->get('channel', 'sharer_interaction_days') . ' day'), $cid, $this->getMedianRelationThreadScore($cid, 4), $cid
|
||||
];
|
||||
} elseif ($this->selectedTab == ChannelEntity::QUIETSHARERS) {
|
||||
$cid = Contact::getPublicIdByUserId($uid);
|
||||
|
||||
$condition = [
|
||||
"`owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `follows` AND `relation-cid` = ? AND `post-score` <= ?)",
|
||||
$cid, $this->getMedianPostScore($cid, 2)
|
||||
];
|
||||
} elseif ($this->selectedTab == ChannelEntity::IMAGE) {
|
||||
$condition = ["`media-type` & ?", 1];
|
||||
} elseif ($this->selectedTab == ChannelEntity::VIDEO) {
|
||||
|
@ -634,6 +641,28 @@ class Timeline extends BaseModule
|
|||
return $score;
|
||||
}
|
||||
|
||||
private function getMedianPostScore(int $cid, int $divider): int
|
||||
{
|
||||
$cache_key = 'Channel:getPostScore:' . $cid . ':' . $divider;
|
||||
$score = $this->cache->get($cache_key);
|
||||
if (!empty($score)) {
|
||||
return $score;
|
||||
}
|
||||
|
||||
$condition = ["`relation-cid` = ? AND `post-score` > ?", $cid, 0];
|
||||
|
||||
$limit = $this->database->count('contact-relation', $condition) / $divider;
|
||||
$relation = $this->database->selectToArray('contact-relation', ['post-score'], $condition, ['order' => ['post-score' => true], 'limit' => [$limit, 1]]);
|
||||
$score = $relation[0]['post-score'] ?? 0;
|
||||
if (empty($score)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$this->cache->set($cache_key, $score, Duration::HALF_HOUR);
|
||||
$this->logger->debug('Calculated median score', ['cid' => $cid, 'divider' => $divider, 'median' => $score]);
|
||||
return $score;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the displayed items.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue