Skip to content

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

https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/10912/commands/39200#visualize-depesz

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 Alper Akgun

Merge request reports