Skip to content

Fix/923 head to head pagination - #935

Closed
knockknock10 wants to merge 6 commits into
ansvisor:mainfrom
knockknock10:fix/923-head-to-head-pagination
Closed

knockknock10 wants to merge 6 commits into
ansvisor:mainfrom
knockknock10:fix/923-head-to-head-pagination

Conversation

@knockknock10

Copy link
Copy Markdown
Contributor

Summary

Fixes an issue where competitor head-to-head comparisons were silently limited to the newest 1,000 prompt_results.

The previous query used select('*') without pagination. Because PostgREST applies the project's 1,000-row max_rows limit, brands with more than 1,000 results could receive incomplete head-to-head statistics.

This PR:

  • Paginates prompt_results using .range() until the final short page.
  • Ensures all results in the queried dataset are included in head-to-head calculations.
  • Selects only the columns required by the comparison instead of loading the full row with select('*').
  • Adds regression tests covering datasets larger than 1,000 rows.
  • Adds coverage for short-page termination and database errors.

Related issue

Closes #923

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

Checklist

Copilot AI balanced review requested due to automatic review settings October 5, 2026 09:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@gkhngyk

gkhngyk commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Thanks, @knockknock10 — this does exactly what #923 suggested, and the tests are solid. The problem is the suggestion itself, which was ours: we didn't check the data volume when writing the issue.

Some brands have well over 100,000 results (the largest has ~200k; ~114k in the last 30 days alone). Paging through all of them means ~200 sequential requests, and getHeadToHeadComparison returns one promptRow per result — including the full answer text and citations — to the browser. For those brands the page would time out or run out of memory, which is worse than today's truncated numbers.

The fix needs the totals and per-platform split aggregated in SQL, and per-prompt summaries instead of one row per result. That needs a migration and is bigger than a first issue, so we'll take #923 ourselves and have updated it with the new approach. Closing this one — thanks again.

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.

bug(competitors): head-to-head is computed from at most the newest 1,000 results

3 participants