Skip to content

fix page 0 and 1 returning same results #233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2025

Conversation

iuwqyir
Copy link
Collaborator

@iuwqyir iuwqyir commented Jul 2, 2025

TL;DR

Fixed pagination logic to use zero-based indexing consistently across all query methods.

What changed?

  • Modified the pagination condition from qf.Page > 0 to qf.Page >= 0 in multiple query methods
  • Changed the offset calculation from (qf.Page - 1) * qf.Limit to qf.Page * qf.Limit in methods where it was still using one-based indexing
  • This ensures consistent zero-based pagination across all database query functions

How to test?

  1. Test API endpoints that use pagination with page=0 parameter
  2. Verify that the first page of results is returned correctly
  3. Test subsequent pages (1, 2, etc.) and confirm proper pagination
  4. Check that no results are duplicated or skipped between pages

Why make this change?

The codebase had inconsistent pagination logic - some methods were using zero-based indexing while others used one-based indexing. This inconsistency could cause confusion for API consumers and potential bugs. This change standardizes all pagination to use zero-based indexing, which is more conventional in programming and aligns with common API practices.

Summary by CodeRabbit

  • Bug Fixes
    • Improved pagination behavior for data queries, ensuring more accurate and consistent results when navigating through pages.

Copy link

coderabbitai bot commented Jul 2, 2025

Walkthrough

The changes update the pagination logic in four functions that construct SQL queries with LIMIT and OFFSET clauses. The offset calculation now uses Page * Limit for any non-negative page number, instead of (Page - 1) * Limit for pages greater than zero. No other logic or function signatures are altered.

Changes

File(s) Change Summary
internal/storage/clickhouse.go Updated pagination logic in four functions to use Page * Limit for offset calculation, allowing page indices starting from zero. No other logic modified.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Storage

    Caller->>Storage: Call function with Page and Limit
    Storage->>Storage: Calculate offset as Page * Limit (Page >= 0)
    Storage->>Storage: Build SQL query with LIMIT and OFFSET
    Storage-->>Caller: Return query results
Loading

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b01a3cd and 6e91935.

📒 Files selected for processing (1)
  • internal/storage/clickhouse.go (4 hunks)
🔇 Additional comments (4)
internal/storage/clickhouse.go (4)

518-519: LGTM! Pagination logic correctly implements zero-based indexing.

The changes properly fix the issue where page 0 and page 1 were returning the same results. Now page 0 returns the first set of results (OFFSET 0) and page 1 returns the second set (OFFSET Limit).


651-652: Consistent pagination fix applied correctly.

The changes match the pattern used in other functions and properly implement zero-based pagination. Since buildQuery is used by multiple query methods (GetBlocks, GetTransactions, GetLogs, GetTraces), this fix ensures consistent pagination behavior across all these endpoints.


1616-1617: Pagination logic consistently updated.

The changes maintain the same zero-based pagination pattern applied throughout the file, ensuring consistent behavior across all query methods.


1707-1709: Pagination logic updated consistently with other functions.

The condition change to qf.Page >= 0 and the offset calculation (line 1708) follow the same zero-based pagination pattern implemented throughout the file, maintaining consistency across all query methods.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Collaborator Author

iuwqyir commented Jul 2, 2025

@iuwqyir iuwqyir requested review from AmineAfia and nischitpra July 2, 2025 11:33
@iuwqyir iuwqyir marked this pull request as ready for review July 2, 2025 11:33
@iuwqyir iuwqyir merged commit fc32b1f into main Jul 2, 2025
6 of 7 checks passed
@iuwqyir iuwqyir deleted the 07-02-fix_page_0_and_1_returning_same_results branch July 2, 2025 11:39
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.

1 participant