-
Notifications
You must be signed in to change notification settings - Fork 55
Skip unnecessary getDocument() for increment upserts #830
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
base: main
Are you sure you want to change the base?
Changes from 2 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 |
|---|---|---|
|
|
@@ -7054,8 +7054,11 @@ public function upsertDocumentsWithIncrease( | |
| $created = 0; | ||
| $updated = 0; | ||
| $seenIds = []; | ||
| $skipPreRead = !empty($attribute); | ||
| foreach ($documents as $key => $document) { | ||
| if ($this->getSharedTables() && $this->getTenantPerDocument()) { | ||
| if ($skipPreRead) { | ||
| $old = new Document(); | ||
| } elseif ($this->getSharedTables() && $this->getTenantPerDocument()) { | ||
| $old = $this->authorization->skip(fn () => $this->withTenant($document->getTenant(), fn () => $this->silent(fn () => $this->getDocument( | ||
| $collection->getId(), | ||
| $document->getId(), | ||
|
|
@@ -7080,9 +7083,12 @@ public function upsertDocumentsWithIncrease( | |
|
|
||
| $regularUpdatesUserOnly = \array_diff_key($regularUpdates, \array_flip($internalKeys)); | ||
|
|
||
| // When skipping pre-read (increment upserts), always skip permission updates. | ||
| // The SQL ON DUPLICATE KEY UPDATE only touches the increment column + _updatedAt, | ||
| // so existing permissions are preserved by the DB, and new docs get empty permissions. | ||
| $skipPermissionsUpdate = true; | ||
|
|
||
| if ($document->offsetExists('$permissions')) { | ||
| if (!$skipPreRead && $document->offsetExists('$permissions')) { | ||
| $originalPermissions = $old->getPermissions(); | ||
|
Comment on lines
+7086
to
7092
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. Explicit permissions are dropped on create-via-increment-upsert. This path now forces 🤖 Prompt for AI Agents
Contributor
Author
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. That's a contradictory usage — you don't set permissions on documents when auth is disabled, because there's no auth layer to enforce them.
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.
✏️ Learnings added
🧠 Learnings used |
||
| $currentPermissions = $document->getPermissions(); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.