backend icon indicating copy to clipboard operation
backend copied to clipboard

Add a stable tiebreaker to the todo list order

Open AlexSergey opened this issue 2 weeks ago • 2 comments

What is wrong

src/features/todos/todos.repository.ts orders the list by one field only ({ [sortBy]: order }). With sortBy=completed or title many rows share a value, so PostgreSQL may return them in a different order on each query, and offset pages (skip/take) can repeat or skip todos.

Why it matters

Clients paging through a sorted list can see duplicates or miss items.

Definition of done

  • orderBy gets a unique tiebreaker, e.g. [{ [sortBy]: order }, { id: 'asc' }].
  • todos.repository.spec.ts is updated for both orderBy cases; npx jest src/features/todos passes.
  • guide/performance.md ("Pagination semantics") mentions the tiebreaker. No migration is needed; note in the PR how it relates to the pending indexes in #19.

Pointers

Performance, section "Use Pagination for Collections".

AlexSergey avatar Nov 15 '26 11:11 AlexSergey

Hi @AlexSergey! If it's still free, I'd like to take this one too. Plan: add { id: 'asc' } as a tiebreaker after the sort field, update both orderBy cases in todos.repository.spec.ts, and mention it in the "Pagination semantics" section of `guide/performance.md".

devmaiter avatar Nov 16 '26 01:11 devmaiter

@devmaiter , thanks, it's yours! One addition from the definition of done: in the PR description, please note how the id tiebreaker relates to the pending indexes in #19 (no migration is needed here). npx jest src/features/todos should pass.

AlexSergey avatar Nov 16 '26 08:11 AlexSergey