Fix performance of To-Do GraphQL API when sorting by created

What does this MR do and why?

Fix performance of To-Do GraphQL API when sorting by created

Todos are created sequentially, so id is a reasonable proxy for created_at. We use this fact to optimize the performance of the finder. We probably could have adjusted the GraphQL enum to allow sorting by id instead and used that in the Frontend, but this would take multiple release cycles and not make it faster for the people who are using CREATED_DESC as a filter in manual queries.

See #502920 (closed)

References

Please include cross links to any resources that are relevant to this MR This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

N/A

How to set up and validate locally

  1. Look at the queries in log/development.log when sorting the todos by created

Before:

SELECT
  "todos".*
FROM
  "todos"
WHERE
  "todos"."user_id" = 113870
  AND ("todos"."state" IN ('done'))
ORDER BY
  "todos"."created_at" DESC,
  "todos"."id" DESC
LIMIT
  21

After:

SELECT
  "todos".*
FROM
  "todos"
WHERE
  "todos"."user_id" = 113870
  AND ("todos"."state" IN ('done'))
ORDER BY
  "todos"."id" DESC
LIMIT
  21
Edited by Lukas Eipert

Merge request reports

Loading
Loading