-
Notifications
You must be signed in to change notification settings - Fork 2k
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
perf(db-mongodb): improve performance of all operations, up to 50% faster #9594
Conversation
…laky fields-relationship int
702091e
to
d2399ed
Compare
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.
Any chance of exporting the transform utility in @payloadcms/db-mongodb
for consumers? It would be useful in cases where we need to perform direct operations with mongo/mongoose.
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.
Don't see why we can't! See 3a68670
Additionally, ensured options.timestamps
prop is respected, since it's mongoose-only, I think you use it
I'd say, actually the only problem with exporting things like this is that they aren't meant to be public and may receive breaking changes.
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.
Thank you for considering the timestamps and exporting! The drawback you mention makes sense. I think we have been using mongoose more as an escape hatch when the adaptor doesn't support what we needed. As more options are added to the adaptor (e.g. select, batchsize, timestamps) we could replace some of those usages with the adapter.
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 think it is fine to export it as-is and add an @expiremental flag to the jsdocs so that anyone using this knows it may change in the future.
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 looked very close at your agregations very closely and it appears you are staying within the API limitations of AWS DocumentDB and Azure Cosmos DB. Great enhancements.
I would only rename the vars cursor
to something else since those aren't being used as DB cursors, just an aggregation.
We can add export and experimental flag as a separate PR for @franciscolourenco to use the new transform, though you could do it now if you want.
05e7c6f
to
dda2f20
Compare
🚀 This is included in version v3.10.0 |
There are few issues introduced in #9594 that we need to look into with these changes.
This PR improves speed and memory efficiency across all operations with the Mongoose adapter.
How?
JSON.parse(JSON.stringify(data))
with thetransform
operation: 'read'
function which converts Date's, ObjectID's in relationships / joins to strings. As before, it also handles transformations for write operations.hasNearConstraint
for potentially largewhere
'straverseFields
now can acceptflattenedFields
which we use intransform
. Less recursive calls with tabs/rows/collapsibleAdditional fixes
buildQuery
, previously it wasn't used which could've led to wrong resultsnull
from the Local API. Previously it didn't work in both, MongoDB and PostgresBenchmarks using this file https://github.com/payloadcms/payload/blob/chore/db-benchmark/test/_community/int.spec.ts
Small Dataset Performance
payload.db.create
(ms)payload.db.find
(ms)payload.db.deleteMany
(ms)payload.db.updateOne
(ms)payload.db.findOne
(ms)payload.db.deleteOne
(ms)Medium Dataset Performance
payload.db.create
(ms)payload.db.find
(ms)payload.db.deleteMany
(ms)payload.db.updateOne
(ms)payload.db.findOne
(ms)payload.db.deleteOne
(ms)Large Dataset Performance
payload.db.create
(ms)payload.db.find
(ms)payload.db.deleteMany
(ms)payload.db.updateOne
(ms)payload.db.findOne
(ms)payload.db.deleteOne
(ms)