Skip to content

Commit 52b189b

Browse files
committed
Chunk id lookups by \$this->maxQueryValues, not RELATION_QUERY_CHUNK_SIZE
CodeRabbit #3084994641 + #3084994657 follow-up: the earlier chunking fix used self::RELATION_QUERY_CHUNK_SIZE (5000), which matches the existing populateDocumentsRelationshipsBatch pattern but doesn't respect the user-configurable validator ceiling. Query::equal('\$id', \$chunk) is validated by DocumentsValidator against \$this->maxQueryValues, not RELATION_QUERY_CHUNK_SIZE. A caller doing \$db->setMaxQueryValues(100) followed by any of the three chunked pre-reads would still throw QueryException because chunks of 5000 exceed the configured 100. Switch to array_chunk(..., max(1, \$this->maxQueryValues)) at all three sites so chunk size always respects the actual validator limit. In the default case (maxQueryValues = 5000) this produces identical chunks to the old code; under customization it correctly scales down. Note: the 5 existing relationship-population chunking sites still use RELATION_QUERY_CHUNK_SIZE and have the same latent bug under customized maxQueryValues. Leaving that for a follow-up since fixing the pattern globally is out of scope for this PR.
1 parent fa0e373 commit 52b189b

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

src/Database/Database.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7159,7 +7159,7 @@ public function upsertDocumentsWithIncrease(
71597159
}
71607160
foreach ($idsByTenant as $tenant => $tenantIds) {
71617161
$tenantIds = \array_values(\array_unique($tenantIds));
7162-
foreach (\array_chunk($tenantIds, self::RELATION_QUERY_CHUNK_SIZE) as $chunk) {
7162+
foreach (\array_chunk($tenantIds, \max(1, $this->maxQueryValues)) as $chunk) {
71637163
$found = $this->authorization->skip(fn () => $this->withTenant($tenant, fn () => $this->silent(
71647164
fn () => $this->find($collection->getId(), [
71657165
Query::equal('$id', $chunk),
@@ -7178,7 +7178,7 @@ public function upsertDocumentsWithIncrease(
71787178
)));
71797179

71807180
if (!empty($docIds)) {
7181-
foreach (\array_chunk($docIds, self::RELATION_QUERY_CHUNK_SIZE) as $chunk) {
7181+
foreach (\array_chunk($docIds, \max(1, $this->maxQueryValues)) as $chunk) {
71827182
$existing = $this->authorization->skip(fn () => $this->silent(
71837183
fn () => $this->find($collection->getId(), [
71847184
Query::equal('$id', $chunk),

src/Database/Mirror.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ public function createDocuments(
612612
));
613613

614614
if (!empty($ids)) {
615-
foreach (\array_chunk(\array_unique($ids), self::RELATION_QUERY_CHUNK_SIZE) as $chunk) {
615+
foreach (\array_chunk(\array_unique($ids), \max(1, $this->maxQueryValues)) as $chunk) {
616616
$existing = $this->source->silent(
617617
fn () => $this->source->find($collection, [
618618
Query::equal('$id', $chunk),

0 commit comments

Comments
 (0)