feat: Add ID-based model chunking#10363
Open
memleakd wants to merge 2 commits into
Open
Conversation
8d27f76 to
761bedd
Compare
- Add chunkById() and chunkRowsById() for primary-key ordered chunking - Reject incompatible builder state like orderBy(), groupBy(), limit(), offset(), and union() - Document ID-based chunking behavior and constraints - Add live model coverage for stable deletion, soft deletes, early exit, and invalid query shapes Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
761bedd to
64042b0
Compare
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds
chunkById()andchunkRowsById()toCodeIgniter\Model.This builds on #9962, which added
chunkRows()for handling whole chunks at once. The existingchunk()andchunkRows()methods use offset-based pagination. This works fine for read-only processing, but it may skip rows when records are updated or deleted while the chunk loop is running.The new methods process records ordered by the model primary key instead:
For cases where the whole chunk should be handled at once:
A few restrictions are added intentionally. Since these methods manage their own primary key cursor and ordering, they cannot be used with
orderBy(),groupBy(),limit(),offset(), orunion(). The model also needs a configured primary key, and the primary key must be selected when custom select clauses are used.This should be useful for jobs, exports, cleanup commands, and other long-running processing where rows may change during iteration.
Tests cover normal processing, early exit, soft deletes, deleting rows while processing, invalid chunk sizes, missing primary key cases, and incompatible builder state.
Checklist: