Skip to content

Proper fix for the count() over() problem#770

Open
vfusco wants to merge 4 commits intonext/2.0from
fix/count-over-problem
Open

Proper fix for the count() over() problem#770
vfusco wants to merge 4 commits intonext/2.0from
fix/count-over-problem

Conversation

@vfusco
Copy link
Collaborator

@vfusco vfusco commented Mar 25, 2026

No description provided.

@vfusco vfusco added this to the 2.0.0 milestone Mar 25, 2026
@vfusco vfusco self-assigned this Mar 25, 2026
@vfusco vfusco requested a review from Copilot March 25, 2026 19:47
Copy link

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 fixes incorrect totalCount results from pagination queries that previously relied on COUNT(*) OVER() (which produces no count when OFFSET skips all rows). It updates Postgres repository list methods to compute totals via a separate COUNT(*) query (in a consistent snapshot) and adjusts synchronization logic/tests to reflect the corrected behavior.

Changes:

  • Replace COUNT(*) OVER() window-count pagination with a separate COUNT(*) query for multiple Postgres List* methods.
  • Add shared helpers to run count + data queries in a read-only, repeatable-read transaction for snapshot consistency.
  • Extend test coverage for the OFFSET >= total rows case and update machine synchronization logic/tests to use correct totals.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/repository/repotest/input_test_cases.go Adds a regression test asserting totalCount remains correct when OFFSET skips all rows.
internal/repository/postgres/util.go Introduces beginReadTx and countFromTx helpers to support correct counting and consistent snapshots.
internal/repository/postgres/tournament.go Switches tournament listing to separate count query + paginated select within a read-only tx.
internal/repository/postgres/state_hash.go Switches state-hash listing to separate count query + paginated select within a read-only tx.
internal/repository/postgres/report.go Switches report listing to separate count query + paginated select within a read-only tx.
internal/repository/postgres/output.go Switches output listing to separate count query + paginated select within a read-only tx.
internal/repository/postgres/match_advanced.go Switches match-advance listing to separate count query + paginated select within a read-only tx.
internal/repository/postgres/match.go Switches match listing to separate count query + paginated select within a read-only tx.
internal/repository/postgres/input.go Switches input listing to separate count query + paginated select within a read-only tx.
internal/repository/postgres/epoch.go Switches epoch listing to separate count query + paginated select within a read-only tx.
internal/repository/postgres/commitment.go Switches commitment listing to separate count query + paginated select within a read-only tx.
internal/repository/postgres/application.go Switches application listing to separate count query + paginated select within a read-only tx.
internal/manager/instance_test.go Updates mock ListInputs total behavior and adds a test ensuring partial-sync scenarios are detected.
internal/manager/instance.go Removes the prior pre-check workaround and adds robust first-batch validation + partial replay detection.

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

@vfusco vfusco force-pushed the fix/count-over-problem branch from bf071e0 to 9c1bfc8 Compare March 26, 2026 01:56
@vfusco vfusco marked this pull request as ready for review March 26, 2026 01:56
@vfusco vfusco requested review from mpolitzer and renatomaia March 26, 2026 01:56
renatomaia
renatomaia previously approved these changes Mar 26, 2026
@github-project-automation github-project-automation bot moved this from Todo to Waiting Merge in Rollups SDK Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Waiting Merge

Development

Successfully merging this pull request may close these issues.

3 participants