Skip to content

Commit f2d687a

Browse files
authored
Merge pull request #576 from utopia-php/feat-upsert-ignore
Skip selects
2 parents 8043176 + c6ed913 commit f2d687a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Database/Database.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4721,18 +4721,18 @@ public function createOrUpdateDocumentsWithIncrease(
47214721
$old = Authorization::skip(fn () => $this->withTenant($document->getTenant(), fn () => $this->silent(fn () => $this->getDocument(
47224722
$collection->getId(),
47234723
$document->getId(),
4724-
[Query::select($selects)],
47254724
))));
47264725
} else {
47274726
$old = Authorization::skip(fn () => $this->silent(fn () => $this->getDocument(
47284727
$collection->getId(),
47294728
$document->getId(),
4730-
[Query::select($selects)],
47314729
)));
47324730
}
47334731

4734-
$disallowed = ['$tenant', '$internalId'];
4735-
if ($old->getArrayCopy(disallow: $disallowed) == $document->getArrayCopy(disallow: $disallowed)) {
4732+
$updatesPermissions = \in_array('$permissions', \array_keys($document->getArrayCopy()))
4733+
&& $document->getPermissions() != $old->getPermissions();
4734+
4735+
if ($old->getAttributes() == $document->getAttributes() && !$updatesPermissions) {
47364736
unset($documents[$key]);
47374737
continue;
47384738
}
@@ -4767,6 +4767,10 @@ public function createOrUpdateDocumentsWithIncrease(
47674767
->setAttribute('$createdAt', empty($createdAt) || !$this->preserveDates ? $time : $createdAt)
47684768
->setAttribute('$updatedAt', empty($updatedAt) || !$this->preserveDates ? $time : $updatedAt);
47694769

4770+
if (!$updatesPermissions) {
4771+
$document->setAttribute('$permissions', $old->getPermissions());
4772+
}
4773+
47704774
if ($this->adapter->getSharedTables()) {
47714775
if ($this->adapter->getTenantPerDocument()) {
47724776
if ($document->getTenant() === null) {

0 commit comments

Comments
 (0)