Skip to content

Conversation

@aarondfrancis
Copy link
Owner

Summary

  • Add $total parameter to fastPaginate() to allow skipping the COUNT query
  • Useful for caching the total count on large tables (10M+ records) where COUNT(*) can take 300ms+
  • Works the same as Laravel's built-in paginate() method

Test plan

  • Added test total_can_be_passed_to_skip_count_query that verifies:
    • Custom total is used instead of running COUNT query
    • Only 2 queries are executed (inner select + outer select) instead of 3
    • The paginator returns the custom total value

🤖 Generated with Claude Code

@coderabbitai
Copy link

coderabbitai bot commented Nov 28, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-74

Comment @coderabbitai help to get the list of available commands and usage tips.

aarondfrancis and others added 2 commits November 27, 2025 21:27
Allow passing a pre-computed total to skip the expensive COUNT(*) query.
This is useful for caching the total count on large tables.

The $total parameter works the same as Laravel's built-in paginate() method.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
aarondfrancis and others added 3 commits November 27, 2025 21:45
Laravel 11+ added a $total parameter to paginate(). Passing this
5th argument to Laravel 10's paginate() causes a TypeError. This
wraps the paginate calls to conditionally pass $total only when
running on Laravel 11+.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
The closure is bound to Eloquent Builder, so it cannot access
protected methods on FastPaginate.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
The $total parameter was added in Laravel 11, so on Laravel 10
we can't skip the COUNT query. The test now only asserts the
query count and custom total on Laravel 11+.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@aarondfrancis aarondfrancis merged commit 2bed7d9 into main Nov 28, 2025
11 checks passed
@aarondfrancis aarondfrancis deleted the fix-74 branch November 28, 2025 04:22
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.

2 participants