Refetch documents by $sequence#916
Conversation
📝 WalkthroughWalkthrough
ChangesRefetch and replay operator-computed documents
Estimated code review effort: 4 (Complex) | ~45 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Greptile SummaryThis PR changes
Confidence Score: 5/5The change is safe to merge; the core logic is correct and system fields including The src/Database/Database.php — specifically the null- Important Files Changed
Reviews (2): Last reviewed commit: "Refetch" | Re-trigger Greptile |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/Database/Database.php (1)
812-842: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winAdd an explicit limit to the refetch query.
find()falls back to a 25-row limit when noQuery::limit()is present, so bulk calls torefetchDocuments()can return stale pre-operator documents for everything past the first 25. UseQuery::limit(count($sequences))here, and chunk the sequence list if needed for adapter limits.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/Database/Database.php` around lines 812 - 842, The refetchDocuments() flow currently calls find() with only a Query::equal('$sequence', $sequences) filter, so it can silently stop at the default 25-result cap. Update the refetch query in Database::refetchDocuments() to include Query::limit(count($sequences)), and if the sequence list can exceed adapter query limits, split the lookup into chunks and merge the results before rebuilding the refetchedMap.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/Database/Database.php`:
- Around line 812-842: The refetchDocuments() flow currently calls find() with
only a Query::equal('$sequence', $sequences) filter, so it can silently stop at
the default 25-result cap. Update the refetch query in
Database::refetchDocuments() to include Query::limit(count($sequences)), and if
the sequence list can exceed adapter query limits, split the lookup into chunks
and merge the results before rebuilding the refetchedMap.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 91a5b9c5-ff4c-40bf-97eb-ffa188eb1459
📒 Files selected for processing (1)
src/Database/Database.php
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/Database/Database.php`:
- Around line 827-833: The refetch logic in refetchDocuments() is still relying
on the default find() limit, so batches larger than 25 can leave later documents
using stale computed/operator values. Update the query passed to
Database::find() to explicitly bound it to the current batch size (or the number
of requested sequence IDs) using Query::limit(), alongside the existing
Query::equal('$sequence', $sequences) and $selections so every document in the
batch is actually refetched.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 0b45f00f-1ddd-49aa-b7e4-a4c42b4548ca
📒 Files selected for processing (1)
src/Database/Database.php
| // Fetch fresh copies with computed operator values, preserving the caller's projection | ||
| $refetched = $this->getAuthorization()->skip(fn () => $this->silent( | ||
| fn () => $this->find($collection->getId(), [Query::equal('$id', $docIds)]) | ||
| fn () => $this->find( | ||
| $collection->getId(), | ||
| array_merge([Query::equal('$sequence', $sequences)], $selections) | ||
| ) | ||
| )); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
Bound the refetch to the batch size
find() defaults to 25 rows, but refetchDocuments() can be called with batches up to INSERT_BATCH_SIZE (1000). Without an explicit Query::limit(), rows past the first 25 fall back to the original $doc via $refetchedMap[$sequences[$index]] ?? $doc, so they keep stale computed/operator values.
Proposed fix
// Fetch fresh copies with computed operator values, preserving the caller's projection
$refetched = $this->getAuthorization()->skip(fn () => $this->silent(
fn () => $this->find(
$collection->getId(),
- array_merge([Query::equal('$sequence', $sequences)], $selections)
+ array_merge([
+ Query::equal('$sequence', $sequences),
+ Query::limit(\count($sequences)),
+ ], $selections)
)
));📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Fetch fresh copies with computed operator values, preserving the caller's projection | |
| $refetched = $this->getAuthorization()->skip(fn () => $this->silent( | |
| fn () => $this->find($collection->getId(), [Query::equal('$id', $docIds)]) | |
| fn () => $this->find( | |
| $collection->getId(), | |
| array_merge([Query::equal('$sequence', $sequences)], $selections) | |
| ) | |
| )); | |
| // Fetch fresh copies with computed operator values, preserving the caller's projection | |
| $refetched = $this->getAuthorization()->skip(fn () => $this->silent( | |
| fn () => $this->find( | |
| $collection->getId(), | |
| array_merge([ | |
| Query::equal('$sequence', $sequences), | |
| Query::limit(\count($sequences)), | |
| ], $selections) | |
| ) | |
| )); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/Database/Database.php` around lines 827 - 833, The refetch logic in
refetchDocuments() is still relying on the default find() limit, so batches
larger than 25 can leave later documents using stale computed/operator values.
Update the query passed to Database::find() to explicitly bound it to the
current batch size (or the number of requested sequence IDs) using
Query::limit(), alongside the existing Query::equal('$sequence', $sequences) and
$selections so every document in the batch is actually refetched.
Summary by CodeRabbit