mirror of
https://github.com/friendica/friendica
synced 2025-04-25 15:50:10 +00:00
Implement correct behavior for min_id in boundary pagination
- The previous behavior of since_id systematically showed the most recent results
This commit is contained in:
parent
e0a6b90316
commit
4427876c05
10 changed files with 101 additions and 59 deletions
|
@ -91,7 +91,7 @@ class FollowRequests extends BaseApi
|
|||
*/
|
||||
public static function rawContent(array $parameters = [])
|
||||
{
|
||||
$since_id = $_GET['since_id'] ?? null;
|
||||
$min_id = $_GET['min_id'] ?? null;
|
||||
$max_id = $_GET['max_id'] ?? null;
|
||||
$limit = intval($_GET['limit'] ?? 40);
|
||||
|
||||
|
@ -100,7 +100,7 @@ class FollowRequests extends BaseApi
|
|||
$introductions = DI::intro()->selectByBoundaries(
|
||||
['`uid` = ? AND NOT `ignore`', self::$current_user_id],
|
||||
['order' => ['id' => 'DESC']],
|
||||
$since_id,
|
||||
$min_id,
|
||||
$max_id,
|
||||
$limit
|
||||
);
|
||||
|
@ -127,7 +127,7 @@ class FollowRequests extends BaseApi
|
|||
}
|
||||
|
||||
if (count($introductions)) {
|
||||
$links[] = '<' . $baseUrl->get() . '/api/v1/follow_requests?' . http_build_query($base_query + ['since_id' => $introductions[0]->id]) . '>; rel="prev"';
|
||||
$links[] = '<' . $baseUrl->get() . '/api/v1/follow_requests?' . http_build_query($base_query + ['min_id' => $introductions[0]->id]) . '>; rel="prev"';
|
||||
}
|
||||
|
||||
header('Link: ' . implode(', ', $links));
|
||||
|
|
|
@ -155,15 +155,24 @@ abstract class ContactEndpoint extends BaseApi
|
|||
|
||||
$total_count = (int)DBA::count('contact', $condition);
|
||||
|
||||
$params = ['limit' => $count, 'order' => ['id' => 'ASC']];
|
||||
|
||||
if ($cursor !== -1) {
|
||||
if ($cursor > 0) {
|
||||
$condition = DBA::mergeConditions($condition, ['`id` > ?', $cursor]);
|
||||
} else {
|
||||
$condition = DBA::mergeConditions($condition, ['`id` < ?', -$cursor]);
|
||||
// Previous page case: we want the items closest to cursor but for that we need to reverse the query order
|
||||
$params['order']['id'] = 'DESC';
|
||||
}
|
||||
}
|
||||
|
||||
$contacts = Contact::selectToArray(['id'], $condition, ['limit' => $count, 'order' => ['id']]);
|
||||
$contacts = Contact::selectToArray(['id'], $condition, $params);
|
||||
|
||||
// Previous page case: once we get the relevant items closest to cursor, we need to restore the expected display order
|
||||
if ($cursor !== -1 && $cursor <= 0) {
|
||||
$contacts = array_reverse($contacts);
|
||||
}
|
||||
|
||||
// Contains user-specific contact ids
|
||||
$ids = array_column($contacts, 'id');
|
||||
|
|
|
@ -44,7 +44,7 @@ class Community extends BaseModule
|
|||
protected static $content;
|
||||
protected static $accounttype;
|
||||
protected static $itemsPerPage;
|
||||
protected static $since_id;
|
||||
protected static $min_id;
|
||||
protected static $max_id;
|
||||
protected static $item_id;
|
||||
|
||||
|
@ -98,8 +98,8 @@ class Community extends BaseModule
|
|||
}
|
||||
$query_parameters = [];
|
||||
|
||||
if (!empty($_GET['since_id'])) {
|
||||
$query_parameters['since_id'] = $_GET['since_id'];
|
||||
if (!empty($_GET['min_id'])) {
|
||||
$query_parameters['min_id'] = $_GET['min_id'];
|
||||
}
|
||||
if (!empty($_GET['max_id'])) {
|
||||
$query_parameters['max_id'] = $_GET['max_id'];
|
||||
|
@ -247,7 +247,7 @@ class Community extends BaseModule
|
|||
self::$item_id = 0;
|
||||
}
|
||||
|
||||
self::$since_id = $_GET['since_id'] ?? null;
|
||||
self::$min_id = $_GET['min_id'] ?? null;
|
||||
self::$max_id = $_GET['max_id'] ?? null;
|
||||
self::$max_id = $_GET['last_commented'] ?? self::$max_id;
|
||||
}
|
||||
|
@ -263,7 +263,7 @@ class Community extends BaseModule
|
|||
*/
|
||||
protected static function getItems()
|
||||
{
|
||||
$items = self::selectItems(self::$since_id, self::$max_id, self::$item_id, self::$itemsPerPage);
|
||||
$items = self::selectItems(self::$min_id, self::$max_id, self::$item_id, self::$itemsPerPage);
|
||||
|
||||
$maxpostperauthor = (int) DI::config()->get('system', 'max_author_posts_community_page');
|
||||
if ($maxpostperauthor != 0 && self::$content == 'local') {
|
||||
|
@ -288,14 +288,14 @@ class Community 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(self::$since_id)) {
|
||||
self::$since_id = $items[0]['commented'];
|
||||
if (isset(self::$min_id)) {
|
||||
self::$min_id = $items[0]['commented'];
|
||||
} else {
|
||||
// In any other case, the lookup continues backwards in time
|
||||
self::$max_id = $items[count($items) - 1]['commented'];
|
||||
}
|
||||
|
||||
$items = self::selectItems(self::$since_id, self::$max_id, self::$item_id, self::$itemsPerPage);
|
||||
$items = self::selectItems(self::$min_id, self::$max_id, self::$item_id, self::$itemsPerPage);
|
||||
}
|
||||
} else {
|
||||
$selected_items = $items;
|
||||
|
@ -307,17 +307,15 @@ class Community extends BaseModule
|
|||
/**
|
||||
* Database query for the comunity page
|
||||
*
|
||||
* @param $since_id
|
||||
* @param $min_id
|
||||
* @param $max_id
|
||||
* @param $itemspage
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
* @TODO Move to repository/factory
|
||||
*/
|
||||
private static function selectItems($since_id, $max_id, $item_id, $itemspage)
|
||||
private static function selectItems($min_id, $max_id, $item_id, $itemspage)
|
||||
{
|
||||
$r = false;
|
||||
|
||||
if (self::$content == 'local') {
|
||||
if (!is_null(self::$accounttype)) {
|
||||
$condition = ["`wall` AND `origin` AND `private` = ? AND `owner`.`contact-type` = ?", Item::PUBLIC, self::$accounttype];
|
||||
|
@ -334,6 +332,8 @@ class Community extends BaseModule
|
|||
return [];
|
||||
}
|
||||
|
||||
$params = ['order' => ['commented' => true], 'limit' => $itemspage];
|
||||
|
||||
if (!empty($item_id)) {
|
||||
$condition[0] .= " AND `iid` = ?";
|
||||
$condition[] = $item_id;
|
||||
|
@ -348,14 +348,26 @@ class Community extends BaseModule
|
|||
$condition[] = $max_id;
|
||||
}
|
||||
|
||||
if (isset($since_id)) {
|
||||
if (isset($min_id)) {
|
||||
$condition[0] .= " AND `commented` > ?";
|
||||
$condition[] = $since_id;
|
||||
$condition[] = $min_id;
|
||||
|
||||
// Previous page case: we want the items closest to min_id but for that we need to reverse the query order
|
||||
if (!isset($max_id)) {
|
||||
$params['order']['commented'] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$r = Item::selectThreadForUser(0, ['uri', 'commented', 'author-link'], $condition, ['order' => ['commented' => true], 'limit' => $itemspage]);
|
||||
$r = Item::selectThreadForUser(0, ['uri', 'commented', 'author-link'], $condition, $params);
|
||||
|
||||
return DBA::toArray($r);
|
||||
$items = DBA::toArray($r);
|
||||
|
||||
// Previous page case: once we get the relevant items closest to min_id, we need to restore the expected display order
|
||||
if (empty($item_id) && isset($min_id) && !isset($max_id)) {
|
||||
$items = array_reverse($items);
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue