Skip to content

Commit 99a9297

Browse files
committed
Improve performance for duplicate resources
1 parent 6a1159e commit 99a9297

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/Serializer.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Serializer
1313
private array $map = [];
1414
private array $primary = [];
1515
private array $deferred = [];
16+
private array $processedFields = [];
1617

1718
/**
1819
* Add a primary resource to the document.
@@ -68,10 +69,12 @@ private function addToMap(Context $context): array
6869
}
6970

7071
foreach ($context->sparseFields($resource) as $field) {
71-
if (has_value($this->map[$key], $field)) {
72+
if (in_array($field, $this->processedFields[$key] ?? [])) {
7273
continue;
7374
}
7475

76+
$this->processedFields[$key][] = $field;
77+
7578
$fieldContext = $context
7679
->withField($field)
7780
->withInclude($context->include[$field->name] ?? null);

0 commit comments

Comments
 (0)