-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Schema Cache Improvements #5612
Conversation
@davimacedo can you take a crack at reviewing? |
Codecov Report
@@ Coverage Diff @@
## master #5612 +/- ##
==========================================
+ Coverage 94.06% 94.11% +0.05%
==========================================
Files 129 129
Lines 9243 9231 -12
==========================================
- Hits 8694 8688 -6
+ Misses 549 543 -6
Continue to review full report at Codecov.
|
@acinader This is ready for review. I edit my original post with comments. |
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.
lgtm. i have a question on one of the tests.
@acinader I rewrote the tests and found more places for improvement. I'll post them up-for-grabs for the community. |
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.
real nice improvement in readability and quality in addition to the better performance.
I have one question about a test that is mystifying me. otherwise, this lgtm
return this._dbAdapter | ||
.getAllClasses() | ||
.then(allSchemas => allSchemas.map(injectDefaultSchema)) | ||
.then(allSchemas => { |
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.
It is a small improvement, but I think we don't need to wait the cache promise to resolve. I'd do something like this::
this._cache.setAllClasses(allSchemas).catch(error => console.error('Error saving schema to cache', error));
return allSchemas;
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 agree
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've just went through all changes and they seem all good to me. I think we are also well covered by the tests. It will bring great improvement for schema cache. LGTM!
* Cache Improvements * improve tests * more tests * clean-up * test with singlecache * ensure indexes exists * remove ALL_KEYS * Add Insert Test * enableSingleSchemaCache default true * Revert "enableSingleSchemaCache default true" This reverts commit 323e713. * further optimization * refactor enforceFieldExists * coverage improvements * improve tests * remove flaky test * cleanup * Learned something new
Closes: #4530
Tested with Redis and enableSingleSchemaCache: true
Significant reduction on creating, updating and deleting objects.
This can be further improved
schema.enforceFieldExist
should be batched for multiple fieldsCould run in parallel instead of chained, should wait to refresh cache after all fields are checked. (Done)
schema.hasClass
could check if class exists then reload if necessaryThis is a tricky one. Only used for allowClientCreation. AddClass and DeleteField clears the cache but maybe it should reload instead (This may come at a performance cost, I haven't done the research but up for discussion).
enableSingleSchemaCache
should be true by defaultTried and caused a few tests to fail. Will do a separate PR.
batch / saveAll / directAccess
Adding class schema before batch will reduce calls in half if it doesn't exist. Adding batchSize > number of objects will result in fewer GET call but 4x as many PUT calls. (Need investigation)