-
Notifications
You must be signed in to change notification settings - Fork 2.7k
perf(db-postgres): simplify db.updateOne
to a single DB call with if the passed data doesn't include nested fields
#13060
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?
Conversation
…f the passed data doesn't include nested fields
|
||
findManyArgs.where = eq(this.tables[tableName].id, idToUpdate) | ||
|
||
const doc = await db.query[tableName].findFirst(findManyArgs) |
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.
Similar to the issue for which I created a PR here, this will return null in a read-replica setup - most of the time.
Hence, causing the transform function to throw an error.
cc: @AlessioGr
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.
I reviewed your PR. You can then pull the latest main
and copy your changes for that line as well.
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.
Thanks for reviewing. Sorry, what do you mean by and copy your changes for that line as well
? Where should I copy it to?
@@ -2809,6 +2807,32 @@ describe('database', () => { | |||
} | |||
}) | |||
|
|||
it('should update simple', async () => { |
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.
I would love to see a in our test that an array
or another kind of hasMany field has data added in the create
and is omitted from the data in updateOne
and assert that it is still present.
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.
Added
📦 esbuild Bundle Analysis for payloadThis analysis was generated by esbuild-bundle-analyzer. 🤖
Largest pathsThese visualization shows top 20 largest paths in the bundle.Meta file: packages/next/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_shared.json, Out file: esbuild/exports/shared.js
Meta file: packages/richtext-lexical/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_shared.json, Out file: esbuild/exports/shared_optimized/index.js
DetailsNext to the size is how much the size has increased or decreased compared with the base branch of this PR.
|
In case, if
payload.db.updateOne
received simple data, meaning no:hasMany: true
text / select / number / relationship fieldsrelationTo
as an arrayThis PR simplifies the logic to a single SQL
set
call. No any extra (useless) steps with rewriting all the arrays / blocks / localized tables even if there were no any changes to them. However, it's good to note thatpayload.update
(notpayload.db.updateOne
) as for now passes all the previous data as well, so this change won't have any effect unless you're usingpayload.db.updateOne
directly (or for our internal logic that uses it), in the future a separate PR with optimization forpayload.update
as well may be implemented.