The source project of this merge request has been removed.
Added creation time-range filters for Snippets API
What does this MR do and why?
Contributes to #336380
Problem
Currently it is possible for pagination to break between calls when listing snippets, if a new snippet is created while a subsequent list API page is being queried. This is because of the way pagination works (stateless, where each page request is evaluated upon receipt).
To provide for a more consistent result, it could help to provide a time filter field such as start
(and also end
) times to clip the results in an API response.
Solution
Used already existing CreatedAtFilterable
and CreatedAtFilter
Raw SQL
SELECT
"snippets".*
FROM
"snippets"
WHERE
"snippets"."visibility_level" = 20
AND "snippets"."project_id" IS NULL
AND "snippets"."visibility_level" = 20
AND "snippets"."created_at" >= '2022-06-22 22:15:12.708000'
ORDER BY
"snippets"."id" DESC
LIMIT 20 OFFSET 0
SELECT
"snippets".*
FROM
"snippets"
WHERE
"snippets"."visibility_level" = 20
AND "snippets"."project_id" IS NULL
AND "snippets"."visibility_level" = 20
AND "snippets"."created_at" <= '2022-06-22 22:15:12.708000'
ORDER BY
"snippets"."id" DESC
LIMIT 20 OFFSET 0
How to test locally
- Checkout the branch.
- Create new Snippets or change the created_at value for the existing public/personal snippets
- In the browser, https://xxxxx.ws-us47.gitpod.io/api/v4/snippets/public?created_after=2020-06-22T22:15:12.708Z
- In the browser, https://xxxxx.ws-us47.gitpod.io/api/v4/snippets/public?created_before=2020-06-22T22:15:12.708Z
Edited by Alper Akgun