-
Notifications
You must be signed in to change notification settings - Fork 54
Feat: Generator (yield) for forEach() #804
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
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📝 WalkthroughWalkthroughAdds a new public iterate(string $collection, array $queries = [], string $forPermission = Database::PERMISSION_READ): \Generator method to yield documents; refactors foreach(...) to delegate to iterate() and invoke the optional callback per yielded document. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@tests/e2e/Adapter/Scopes/DocumentTests.php`:
- Around line 4017-4026: The test creates an empty collection 'moviesEmpty' but
the foreach iterates 'movies', causing the assertion to fail; update the call to
$database->foreach(...) to pass 'moviesEmpty' (keeping the existing queries:
[Query::limit(2)] and the rest of the loop intact) so the loop iterates the
newly created empty collection and the count assertion becomes valid.
There was a problem hiding this 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 Database::foreach() to support iterating documents via yield when no callback is provided, and extends the E2E tests to cover the new iteration mode (including empty collections).
Changes:
- Changed
Database::foreach()signature to allow a nullable callback and to return a\Generator. - Added yielding behavior when no callback is provided.
- Added E2E tests for iterating with no callback (empty and non-empty collections).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/Database/Database.php |
Adds generator-based iteration mode to foreach() when no callback is provided. |
tests/e2e/Adapter/Scopes/DocumentTests.php |
Adds coverage for callback-less foreach() usage and empty-collection behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/Database/Database.php`:
- Around line 7876-7887: The PHPDoc for the method iterate() is out of sync with
its signature: remove the stale "@param callable $callback" entry and update the
description to state that the method yields documents via a Generator for the
given $collection and $queries; keep or adjust the existing `@param` annotations
to only list "string $collection", "array<Query> $queries", and "string
$forPermission" (default Database::PERMISSION_READ), retain "@return \Generator"
and any relevant `@throws`, and ensure the docblock accurately describes that
iterate() yields results rather than accepting a callback.
Summary by CodeRabbit
Refactor
Tests