Refactor Conversation Timeline

pull/14559/head
Art4 2024-11-18 22:00:02 +00:00
rodzic c79f3cde22
commit ec0c3bf96e
2 zmienionych plików z 60 dodań i 49 usunięć

Wyświetl plik

@ -7,7 +7,8 @@
namespace Friendica\Module\Conversation;
use Friendica\App;
use Friendica\App\Arguments;
use Friendica\App\BaseURL;
use Friendica\App\Mode;
use Friendica\BaseModule;
use Friendica\Content\Conversation\Collection\Timelines;
@ -31,6 +32,8 @@ use Friendica\Model\Post;
use Friendica\Model\Post\Engagement;
use Friendica\Model\Post\SearchIndex;
use Friendica\Module\Response;
use Friendica\Network\HTTPException\BadRequestException;
use Friendica\Network\HTTPException\ForbiddenException;
use Friendica\Protocol\Activity;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Profiler;
@ -67,7 +70,7 @@ class Timeline extends BaseModule
/** @var string */
protected $network;
/** @var App\Mode $mode */
/** @var Mode $mode */
protected $mode;
/** @var IHandleUserSessions */
protected $session;
@ -82,7 +85,7 @@ class Timeline extends BaseModule
/** @var UserDefinedChannel */
protected $channelRepository;
public function __construct(UserDefinedChannel $channel, Mode $mode, IHandleUserSessions $session, Database $database, IManagePersonalConfigValues $pConfig, IManageConfigValues $config, ICanCache $cache, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server = [], array $parameters = [])
public function __construct(UserDefinedChannel $channel, Mode $mode, IHandleUserSessions $session, Database $database, IManagePersonalConfigValues $pConfig, IManageConfigValues $config, ICanCache $cache, L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server = [], array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
@ -98,8 +101,8 @@ class Timeline extends BaseModule
/**
* Computes module parameters from the request and local configuration
*
* @throws HTTPException\BadRequestException
* @throws HTTPException\ForbiddenException
* @throws BadRequestException
* @throws ForbiddenException
*/
protected function parseRequest(array $request)
{
@ -308,6 +311,8 @@ class Timeline extends BaseModule
{
$table = 'post-engagement';
$condition = [];
if ($this->selectedTab == ChannelEntity::WHATSHOT) {
if (!is_null($this->accountType)) {
$condition = ["(`comments` > ? OR `activities` > ?) AND `contact-type` = ?", $this->getMedianComments($uid, 4), $this->getMedianActivities($uid, 4), $this->accountType];
@ -331,11 +336,11 @@ class Timeline extends BaseModule
"`owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND NOT `follows`) AND
(`owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND NOT `follows` AND `relation-thread-score` > ?) OR
`owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `cid` = ? AND `relation-thread-score` > ?) OR
((`comments` >= ? OR `activities` >= ?) AND
(`owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `cid` = ? AND `relation-thread-score` > ?)) OR
((`comments` >= ? OR `activities` >= ?) AND
(`owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `cid` = ? AND `relation-thread-score` > ?)) OR
(`owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `relation-thread-score` > ?))))",
$cid, $cid, $this->getMedianRelationThreadScore($cid, 4), $cid, $this->getMedianRelationThreadScore($cid, 4),
$this->getMedianComments($uid, 4), $this->getMedianActivities($uid, 4), $cid, 0, $cid, 0
$this->getMedianComments($uid, 4), $this->getMedianActivities($uid, 4), $cid, 0, $cid, 0
];
} elseif ($this->selectedTab == ChannelEntity::FOLLOWERS) {
@ -490,7 +495,7 @@ class Timeline extends BaseModule
$placeholders = substr(str_repeat("?, ", count($search)), 0, -2);
$condition = DBA::mergeConditions($condition, array_merge(["`uri-id` IN (SELECT `uri-id` FROM `post-tag` INNER JOIN `tag` ON `tag`.`id` = `post-tag`.`tid` WHERE `post-tag`.`type` = 1 AND `name` IN (" . $placeholders . "))"], $search));
}
if (!empty($channel->excludeTags)) {
$search = explode(',', mb_strtolower($channel->excludeTags));
$placeholders = substr(str_repeat("?, ", count($search)), 0, -2);
@ -500,7 +505,7 @@ class Timeline extends BaseModule
if (!empty($channel->mediaType)) {
$condition = DBA::mergeConditions($condition, ["`media-type` & ?", $channel->mediaType]);
}
// For "addLanguageCondition" to work, the condition must not be empty
$condition = $this->addLanguageCondition($uid, $condition ?: ["true"], $channel->languages);
}
@ -684,6 +689,7 @@ class Timeline extends BaseModule
protected function getCommunityItems()
{
$items = $this->selectItems();
$key = '';
if ($this->selectedTab == Community::LOCAL) {
$maxpostperauthor = (int)$this->config->get('system', 'max_author_posts_community_page');
@ -692,49 +698,52 @@ class Timeline extends BaseModule
$maxpostperauthor = (int)$this->config->get('system', 'max_server_posts_community_page');
$key = 'author-gsid';
} else {
$maxpostperauthor = 0;
$this->setItemsSeenByCondition([
'unseen' => true,
'uid' => $this->session->getLocalUserId(),
'parent-uri-id' => array_column($items, 'uri-id')
]);
return $items;
}
if ($maxpostperauthor != 0) {
$count = 1;
$author_posts = [];
$selected_items = [];
while (count($selected_items) < $this->itemsPerPage && ++$count < 50 && count($items) > 0) {
$maxposts = round((count($items) / $this->itemsPerPage) * $maxpostperauthor);
$minId = $items[array_key_first($items)]['received'];
$maxId = $items[array_key_last($items)]['received'];
$count = 1;
$author_posts = [];
$selected_items = [];
foreach ($items as $item) {
$author_posts[$item[$key]][$item['uri-id']] = $item['received'];
while (count($selected_items) < $this->itemsPerPage && ++$count < 50 && count($items) > 0) {
$maxposts = round((count($items) / $this->itemsPerPage) * $maxpostperauthor);
$minId = $items[array_key_first($items)]['received'];
$maxId = $items[array_key_last($items)]['received'];
foreach ($items as $item) {
$author_posts[$item[$key]][$item['uri-id']] = $item['received'];
}
foreach ($author_posts as $posts) {
if (count($posts) <= $maxposts) {
continue;
}
foreach ($author_posts as $posts) {
if (count($posts) <= $maxposts) {
continue;
}
asort($posts);
while (count($posts) > $maxposts) {
$uri_id = array_key_first($posts);
unset($posts[$uri_id]);
unset($items[$uri_id]);
}
}
$selected_items = array_merge($selected_items, $items);
// If we're looking at a "previous page", the lookup continues forward in time because the list is
// sorted in chronologically decreasing order
if (!empty($this->minId)) {
$this->minId = $minId;
} else {
// In any other case, the lookup continues backwards in time
$this->maxId = $maxId;
}
if (count($selected_items) < $this->itemsPerPage) {
$items = $this->selectItems();
asort($posts);
while (count($posts) > $maxposts) {
$uri_id = array_key_first($posts);
unset($posts[$uri_id]);
unset($items[$uri_id]);
}
}
} else {
$selected_items = $items;
$selected_items = array_merge($selected_items, $items);
// If we're looking at a "previous page", the lookup continues forward in time because the list is
// sorted in chronologically decreasing order
if (!empty($this->minId)) {
$this->minId = $minId;
} else {
// In any other case, the lookup continues backwards in time
$this->maxId = $maxId;
}
if (count($selected_items) < $this->itemsPerPage) {
$items = $this->selectItems();
}
}
$condition = ['unseen' => true, 'uid' => $this->session->getLocalUserId(), 'parent-uri-id' => array_column($selected_items, 'uri-id')];
@ -808,7 +817,7 @@ class Timeline extends BaseModule
}
$uriids = array_keys($items);
foreach (Post\Counts::get(['parent-uri-id' => $uriids, 'verb' => Activity::POST]) as $count) {
$items[$count['parent-uri-id']]['comments'] += $count['count'];
}

Wyświetl plik

@ -565,6 +565,8 @@ class Probe
$nick = '';
$addr = '';
$path_parts = [];
if (array_key_exists('path', $parts) && trim(strval($parts['path']), '/') !== '') {
$path_parts = explode('/', trim($parts['path'], '/'));
@ -578,7 +580,7 @@ class Probe
}
if (empty($webfinger) && empty($lrdd)) {
while (empty($lrdd) && empty($webfinger) && (sizeof($path_parts) > 1)) {
while (empty($lrdd) && empty($webfinger) && (count($path_parts) > 1)) {
$host .= '/' . array_shift($path_parts);
$baseurl = $parts['scheme'] . '://' . $host;