Skip to content

Added creation time-range filters for Snippets API

What does this MR do and why?

Contributes to #336380 . There was a previous MR at !90999 (closed) but the source project was deleted so this MR was recreated. This MR may contain more context as there were a few rounds of review already.

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

Edited by Dylan Griffith

Merge request reports