mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-05-15 12:36:26 +02:00
Add strategy for more efficient pagination in API listing of entries by using before_id and after_id wheres instead of pagination if possible
This commit is contained in:
parent
04b0f1267a
commit
0e11bcda17
10 changed files with 156 additions and 28 deletions
models
|
@ -70,12 +70,22 @@ namespace models;
|
|||
* @param int $id_user : user id
|
||||
* @param int $limit : Number of entry to return
|
||||
* @param int $offset : Number of entry to ignore
|
||||
* @param ?int $after_id : If provided use where id > $after_id instead of offset
|
||||
* @param ?int $before_id : If provided use where id < $before_id instead of offset
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list_for_user(int $id_user, $limit, $offset)
|
||||
public function list_for_user(int $id_user, $limit, $offset, ?int $after_id = null, ?int $before_id = null)
|
||||
{
|
||||
return $this->_select($this->get_table_name(), ['id_user' => $id_user], null, false, $limit, $offset);
|
||||
if ($after_id !== null) {
|
||||
return $this->_select($this->get_table_name(), ['id_user' => $id_user, '>id' => $after_id], 'id', false, $limit);
|
||||
}
|
||||
|
||||
if ($before_id !== null) {
|
||||
return array_reverse($this->_select($this->get_table_name(), ['id_user' => $id_user, '<id' => $before_id], 'id', true, $limit));
|
||||
}
|
||||
|
||||
return $this->_select($this->get_table_name(), ['id_user' => $id_user], 'id', false, $limit, $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue