Repository navigation
Revert relationship max queries #973
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,91 +26,6 @@ trait RelationshipTests | |
| use ManyToOneTests; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This deleted test exercised observable public behavior: complete relationship population when an internal lookup crosses the configured query-value boundary. It did not inspect chunk sizes or internal calls. Removing the only coverage of this boundary across relationship types and directions allows the exact failure introduced here to pass while ordinary relationship tests remain green. Retain a behavior-focused version and remove only the redundant direct-query exception assertion. Prompt To Fix With AIThis is a comment left during a code review.
Path: tests/e2e/Adapter/Scopes/RelationshipTests.php
Line: 26
Comment:
**Behavioral regression coverage removed**
This deleted test exercised observable public behavior: complete relationship population when an internal lookup crosses the configured query-value boundary. It did not inspect chunk sizes or internal calls. Removing the only coverage of this boundary across relationship types and directions allows the exact failure introduced here to pass while ordinary relationship tests remain green. Retain a behavior-focused version and remove only the redundant direct-query exception assertion.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
| use ManyToManyTests; | ||
|
|
||
| /** | ||
| * @return array<string, array{string, string, int}> | ||
| */ | ||
| public static function relationshipQueryValueLimitProvider(): array | ||
| { | ||
| $cases = []; | ||
| foreach ([Database::RELATION_ONE_TO_ONE, Database::RELATION_ONE_TO_MANY, Database::RELATION_MANY_TO_ONE, Database::RELATION_MANY_TO_MANY] as $type) { | ||
| foreach (['parents', 'children'] as $collection) { | ||
| $cases[$type . ' ' . $collection] = [$type, $collection, 3]; | ||
| } | ||
| } | ||
|
|
||
| // One parent can exceed the value limit when fetching its related documents. | ||
| $cases['manyToMany related documents'] = [Database::RELATION_MANY_TO_MANY, 'parents', 1]; | ||
|
|
||
| return $cases; | ||
| } | ||
|
|
||
| /** | ||
| * @dataProvider relationshipQueryValueLimitProvider | ||
| */ | ||
| public function testRelationshipQueryValueLimit(string $type, string $collection, int $limit): void | ||
| { | ||
| $database = $this->getDatabase(); | ||
|
|
||
| if (!$database->getAdapter()->getSupportForRelationships()) { | ||
| $this->expectNotToPerformAssertions(); | ||
| return; | ||
| } | ||
|
|
||
| $parents = ID::unique(); | ||
| $children = ID::unique(); | ||
| $permissions = [ | ||
| Permission::read(Role::any()), | ||
| Permission::create(Role::any()), | ||
| Permission::update(Role::any()), | ||
| Permission::delete(Role::any()), | ||
| ]; | ||
| $database->createCollection($parents, permissions: $permissions); | ||
| $database->createCollection($children, permissions: $permissions); | ||
| $database->createRelationship($parents, $children, $type, true, 'children', 'parents'); | ||
|
|
||
| foreach (['child1', 'child2', 'child3'] as $id) { | ||
| $database->createDocument($children, new Document(['$id' => $id])); | ||
| } | ||
|
|
||
| for ($i = 1; $i <= 3; $i++) { | ||
| $related = match ($type) { | ||
| Database::RELATION_MANY_TO_MANY => ['child1', 'child2', 'child3'], | ||
| Database::RELATION_ONE_TO_MANY => ['child' . $i], | ||
| default => 'child' . $i, | ||
| }; | ||
| $database->createDocument($parents, new Document([ | ||
| '$id' => 'parent' . $i, | ||
| 'children' => $related, | ||
| ])); | ||
| } | ||
|
|
||
| $max = $database->getMaxQueryValues(); | ||
| $database->setMaxQueryValues(2); | ||
|
|
||
| try { | ||
| $documents = $database->find($collection === 'parents' ? $parents : $children, [Query::limit($limit)]); | ||
|
|
||
| $this->assertCount($limit, $documents); | ||
| foreach ($documents as $document) { | ||
| $related = $document->getAttribute($collection === 'parents' ? 'children' : 'parents'); | ||
| $related = $related instanceof Document ? [$related] : $related; | ||
| $ids = \array_map(fn (Document $related) => $related->getId(), $related); | ||
| $prefix = $collection === 'parents' ? 'child' : 'parent'; | ||
| $expected = $type === Database::RELATION_MANY_TO_MANY | ||
| ? [$prefix . '1', $prefix . '2', $prefix . '3'] | ||
| : [$prefix . \substr($document->getId(), -1)]; | ||
| $this->assertEqualsCanonicalizing($expected, $ids); | ||
| } | ||
|
|
||
| $this->expectException(QueryException::class); | ||
| $database->find($children, [Query::equal('$id', ['child1', 'child2', 'child3'])]); | ||
| } finally { | ||
| $database->setMaxQueryValues($max); | ||
| $database->deleteCollection($parents); | ||
| $database->deleteCollection($children); | ||
| } | ||
| } | ||
|
|
||
| public function testZoo(): void | ||
| { | ||
| /** @var Database $database */ | ||
|
|
||
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.
When
setMaxQueryValues(5)is used, populating six or more unique relationship IDs now creates a chunk larger than the configured limit. The internalfind()call validates that chunk against the same limit and throwsQueryException, so an otherwise valid relationship read fails instead of being split into executable queries. The same fixed chunk size is used in the other relationship-loading paths at lines 5420, 5517, 5596, and 5626.Knowledge Base Used:
Prompt To Fix With AI