+
+ private static function getMedianComments(int $divider): int
+ {
+ $cache_key = 'Channel:getMedianComments:' . $divider;
+ $comments = DI::cache()->get($cache_key);
+ if (!empty($comments)) {
+ return $comments;
+ }
+
+ $limit = DBA::count('post-engagement', ["`contact-type` != ? AND `comments` > ?", Contact::TYPE_COMMUNITY, 0]) / $divider;
+ $post = DBA::selectToArray('post-engagement', ['comments'], ["`contact-type` != ?", Contact::TYPE_COMMUNITY, 0], ['order' => ['comments' => true], 'limit' => [$limit, 1]]);
+ $comments = $post[0]['comments'] ?? 0;
+ if (empty($comments)) {
+ return 0;
+ }
+
+ DI::cache()->set($cache_key, $comments, Duration::HOUR);
+ 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;
+ $score = DI::cache()->get($cache_key);
+ if (!empty($score)) {
+ return $score;
+ }
+
+ $limit = DBA::count('contact-relation', ["`cid` = ? AND `thread-score` > ?", $cid, 0]) / $divider;
+ $relation = DBA::selectToArray('contact-relation', ['thread-score'], ['cid' => $cid], ['order' => ['thread-score' => true], 'limit' => [$limit, 1]]);
+ $score = $relation[0]['thread-score'] ?? 0;
+ if (empty($score)) {
+ return 0;
+ }
+
+ DI::cache()->set($cache_key, $score, Duration::HOUR);
+ return $score;
+ }