Skip to content

apply sort before pagination in experiments and segments#3101

Open
bcb37 wants to merge 2 commits intodevfrom
fix/2894-apply-sort-first
Open

apply sort before pagination in experiments and segments#3101
bcb37 wants to merge 2 commits intodevfrom
fix/2894-apply-sort-first

Conversation

@bcb37
Copy link
Copy Markdown
Collaborator

@bcb37 bcb37 commented May 6, 2026

No description provided.

Co-authored-by: Copilot <copilot@github.com>
danoswaltCL
danoswaltCL previously approved these changes May 6, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates backend pagination queries for segments and experiments so that sorting is applied before offset/limit, preventing inconsistent page contents when a sort is requested.

Changes:

  • Apply ORDER BY to the parent subquery used for pagination in SegmentService.findPaginated.
  • Refactor the experiments pagination subquery to use GROUP BY experiment.id (instead of DISTINCT) so it can be ordered by the requested sort key prior to pagination.
  • Add stable secondary ordering (... , id ASC) for segments to ensure deterministic results when the primary sort key contains ties.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/backend/src/api/services/SegmentService.ts Adds ordering (including id tiebreaker) to the paginated subquery and aligns the outer query ordering accordingly.
packages/backend/src/api/services/ExperimentService.ts Refactors the paginated subquery to GROUP BY and orders by the requested sort key (and id) prior to applying pagination.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/backend/src/api/services/ExperimentService.ts
Co-authored-by: Copilot <copilot@github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread packages/backend/src/api/services/ExperimentService.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Experiments / Segments root tables reorder rows when loading more data on scroll

3 participants