mirror of
https://github.com/friendica/friendica
synced 2025-04-25 03:10:11 +00:00
Fix the erratic page update behaviour
This commit is contained in:
parent
aa6eb7fcf1
commit
e038890bb7
9 changed files with 107 additions and 49 deletions
|
@ -62,6 +62,8 @@ class Timeline extends BaseModule
|
|||
protected $itemsPerPage;
|
||||
/** @var bool */
|
||||
protected $noSharer;
|
||||
/** @var bool */
|
||||
protected $force;
|
||||
|
||||
/** @var App\Mode $mode */
|
||||
protected $mode;
|
||||
|
@ -129,6 +131,7 @@ class Timeline extends BaseModule
|
|||
$this->maxId = $request['max_id'] ?? null;
|
||||
|
||||
$this->noSharer = !empty($request['no_sharer']);
|
||||
$this->force = !empty($request['force']);
|
||||
}
|
||||
|
||||
protected function getNoSharerWidget(string $base): string
|
||||
|
@ -191,31 +194,47 @@ class Timeline extends BaseModule
|
|||
{
|
||||
$items = $this->getRawChannelItems();
|
||||
|
||||
$contacts = $this->database->selectToArray('user-contact', ['cid'], ['channel-visibility' => Contact\User::VISIBILITY_REDUCED, 'cid' => array_column($items, 'owner-id')]);
|
||||
$contacts = $this->database->selectToArray('user-contact', ['cid'], ['channel-frequency' => Contact\User::FREQUENCY_REDUCED, 'cid' => array_column($items, 'owner-id')]);
|
||||
$reduced = array_column($contacts, 'cid');
|
||||
|
||||
$maxpostperauthor = $this->config->get('channel', 'max_posts_per_author');
|
||||
|
||||
if ($maxpostperauthor != 0) {
|
||||
$count = 1;
|
||||
$numposts = [];
|
||||
$owner_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)]['created'];
|
||||
$maxId = $items[array_key_last($items)]['created'];
|
||||
|
||||
foreach ($items as $item) {
|
||||
$numposts[$item['owner-id']] = ($numposts[$item['owner-id']] ?? 0);
|
||||
if (!in_array($item['owner-id'], $reduced) || (($numposts[$item['owner-id']]++ < $maxpostperauthor)) && (count($selected_items) < $this->itemsPerPage)) {
|
||||
$selected_items[] = $item;
|
||||
if (!in_array($item['owner-id'], $reduced)) {
|
||||
continue;
|
||||
}
|
||||
$owner_posts[$item['owner-id']][$item['uri-id']] = (($item['comments'] * 100) + $item['activities']);
|
||||
}
|
||||
foreach ($owner_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 (isset($this->minId)) {
|
||||
$this->minId = $items[0]['created'];
|
||||
if (!empty($this->minId)) {
|
||||
$this->minId = $minId;
|
||||
} else {
|
||||
// In any other case, the lookup continues backwards in time
|
||||
$this->maxId = $items[count($items) - 1]['created'];
|
||||
$this->maxId = $maxId;
|
||||
}
|
||||
|
||||
if (count($selected_items) < $this->itemsPerPage) {
|
||||
|
@ -254,9 +273,9 @@ class Timeline extends BaseModule
|
|||
$condition = [
|
||||
"(`owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `relation-thread-score` > ?) OR
|
||||
((`comments` >= ? OR `activities` >= ?) AND `owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `follows` AND `relation-cid` = ?)) OR
|
||||
(`owner-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND (`notify_new_posts` OR `channel-visibility` = ?))))",
|
||||
(`owner-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND (`notify_new_posts` OR `channel-frequency` = ?))))",
|
||||
$cid, $this->getMedianRelationThreadScore($cid, 4), $this->getMedianComments($uid, 4), $this->getMedianActivities($uid, 4), $cid,
|
||||
$uid, Contact\User::VISIBILITY_ALWAYS
|
||||
$uid, Contact\User::FREQUENCY_ALWAYS
|
||||
];
|
||||
} elseif ($this->selectedTab == TimelineEntity::FOLLOWERS) {
|
||||
$condition = ["`owner-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` = ?)", $uid, Contact::FOLLOWER];
|
||||
|
@ -284,7 +303,7 @@ class Timeline extends BaseModule
|
|||
$condition = $this->addLanguageCondition($uid, $condition);
|
||||
}
|
||||
|
||||
$condition = DBA::mergeConditions($condition, ["NOT EXISTS(SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` = `post-engagement`.`owner-id` AND (`ignored` OR `blocked` OR `collapsed` OR `is-blocked` OR `channel-visibility` = ?))", $uid, Contact\User::VISIBILITY_NEVER]);
|
||||
$condition = DBA::mergeConditions($condition, ["NOT EXISTS(SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` = `post-engagement`.`owner-id` AND (`ignored` OR `blocked` OR `collapsed` OR `is-blocked` OR `channel-frequency` = ?))", $uid, Contact\User::FREQUENCY_NEVER]);
|
||||
|
||||
if (($this->selectedTab != TimelineEntity::WHATSHOT) && !is_null($this->accountType)) {
|
||||
$condition = DBA::mergeConditions($condition, ['contact-type' => $this->accountType]);
|
||||
|
@ -313,14 +332,20 @@ class Timeline extends BaseModule
|
|||
}
|
||||
}
|
||||
|
||||
$items = $this->database->selectToArray('post-engagement', ['uri-id', 'created', 'owner-id'], $condition, $params);
|
||||
$items = [];
|
||||
$result = $this->database->select('post-engagement', ['uri-id', 'created', 'owner-id', 'comments', 'activities'], $condition, $params);
|
||||
while ($item = $this->database->fetch($result)) {
|
||||
$items[$item['uri-id']] = $item;
|
||||
}
|
||||
$this->database->close($result);
|
||||
|
||||
if (empty($items)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Previous page case: once we get the relevant items closest to min_id, we need to restore the expected display order
|
||||
if (empty($this->itemUriId) && isset($this->minId) && !isset($this->maxId)) {
|
||||
$items = array_reverse($items);
|
||||
$items = array_reverse($items, true);
|
||||
}
|
||||
|
||||
$condition = ['unseen' => true, 'uid' => $uid, 'parent-uri-id' => array_column($items, 'uri-id')];
|
||||
|
@ -451,10 +476,10 @@ class Timeline extends BaseModule
|
|||
// If we're looking at a "previous page", the lookup continues forward in time because the list is
|
||||
// sorted in chronologically decreasing order
|
||||
if (isset($this->minId)) {
|
||||
$this->minId = $items[0]['commented'];
|
||||
$this->minId = $items[0]['received'];
|
||||
} else {
|
||||
// In any other case, the lookup continues backwards in time
|
||||
$this->maxId = $items[count($items) - 1]['commented'];
|
||||
$this->maxId = $items[count($items) - 1]['received'];
|
||||
}
|
||||
|
||||
$items = $this->selectItems();
|
||||
|
@ -479,22 +504,18 @@ class Timeline extends BaseModule
|
|||
private function selectItems()
|
||||
{
|
||||
if ($this->selectedTab == 'local') {
|
||||
if (!is_null($this->accountType)) {
|
||||
$condition = ["`wall` AND `origin` AND `private` = ? AND `owner-contact-type` = ?", Item::PUBLIC, $this->accountType];
|
||||
} else {
|
||||
$condition = ["`wall` AND `origin` AND `private` = ?", Item::PUBLIC];
|
||||
}
|
||||
$condition = ["`wall` AND `origin` AND `private` = ?", Item::PUBLIC];
|
||||
} elseif ($this->selectedTab == 'global') {
|
||||
if (!is_null($this->accountType)) {
|
||||
$condition = ["`uid` = ? AND `private` = ? AND `owner-contact-type` = ?", 0, Item::PUBLIC, $this->accountType];
|
||||
} else {
|
||||
$condition = ["`uid` = ? AND `private` = ?", 0, Item::PUBLIC];
|
||||
}
|
||||
$condition = ["`uid` = ? AND `private` = ?", 0, Item::PUBLIC];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
|
||||
$params = ['order' => ['commented' => true], 'limit' => $this->itemsPerPage];
|
||||
if (!is_null($this->accountType)) {
|
||||
$condition = DBA::mergeConditions($condition, ['owner-contact-type' => $this->accountType]);
|
||||
}
|
||||
|
||||
$params = ['order' => ['received' => true], 'limit' => $this->itemsPerPage];
|
||||
|
||||
if (!empty($this->itemUriId)) {
|
||||
$condition = DBA::mergeConditions($condition, ['uri-id' => $this->itemUriId]);
|
||||
|
@ -504,20 +525,20 @@ class Timeline extends BaseModule
|
|||
}
|
||||
|
||||
if (isset($this->maxId)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`commented` < ?", $this->maxId]);
|
||||
$condition = DBA::mergeConditions($condition, ["`received` < ?", $this->maxId]);
|
||||
}
|
||||
|
||||
if (isset($this->minId)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`commented` > ?", $this->minId]);
|
||||
$condition = DBA::mergeConditions($condition, ["`received` > ?", $this->minId]);
|
||||
|
||||
// Previous page case: we want the items closest to min_id but for that we need to reverse the query order
|
||||
if (!isset($this->maxId)) {
|
||||
$params['order']['commented'] = false;
|
||||
$params['order']['received'] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$r = Post::selectThreadForUser($this->session->getLocalUserId() ?: 0, ['uri-id', 'commented', 'author-link'], $condition, $params);
|
||||
$r = Post::selectThreadForUser($this->session->getLocalUserId() ?: 0, ['uri-id', 'received', 'author-link'], $condition, $params);
|
||||
|
||||
$items = Post::toArray($r);
|
||||
if (empty($items)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue