-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
WIP: Reduces number of calls to _SCHEMA #1387
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
Conversation
Current coverage is
|
return this.schemaPromise.then((schema) => { | ||
DatabaseController.prototype.invalidateSchema = function() { | ||
delete this._schema; | ||
delete this.schemaPromise; |
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 don't think you should delete this promise, as it is a outstanding request to refresh the schema, This would actually make performance worse.
this function should just be delete this._schema
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.
We can get in a lock if we don't delete the promise and only the schema
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.
You would still need to delete this.schemaPromise
in the _loadSchema
function similar to how it was originally
Compare these two scenarios where the server gets two requests (R1
,R2
) in quick succession, Say a initial page load that does couple queries
With the setup in this pull request
R1.invalidateSchema
R1._loadSchema
R1.schemaCollection // creates schemaPromise (Queries _SCHEMA)
R2.invalidateSchema // deletes schemaPromise before it has even returned
R2._loadSchema
R2.schemaCollection // creates schemaPromise (Queries _SCHEMA)
// R1.schemaCollection query resolves
// R2.schemaCollection query resolves
// This would result in two concurrent _SCHEMA queries
If you moved the delete this.scehamPromise
into the _loadSchema
R1.invalidateSchema
R1._loadSchema
R1.schemaCollection // creates schemaPromise (Queries _SCHEMA)
R2.invalidateSchema // doesnt delete schemaPromise
R2._loadSchema
// R1.schemaCollection resolves
// R1 deletes schemaPromise
// R2 resolves from R1.schemaCollection resolution
// This would result in only one _SCHEMA query
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.
very very good point!
@flovilmart updated the pull request. |
Could we lock the _SCHEMA when the server starts in production mode? Do people need to be able add/remove fields on the fly in production mode? If we could lock it, then It would only be one _SCHEMA call when the server starts. In dev mode the _SCHEMA could be queried before every request |
We do currently change the schema without server restarts, e.g.1: preparing an updated schema for an upcoming deploy without affecting the live service. E.g.2: performing cleanup on the schema (removing old fields) while the service is running. I'm happy with the idea of the original PR and wouldn't want optimisation to reduce capabilities we currently enjoy. It will be worth profiling this change. |
by default NODE_ENV=production is set on heroku or other servers, implementing that way relying on the production flag would render many deployments faulty in the eyes of many users. |
cb8c123
to
896f62b
Compare
@flovilmart updated the pull request. |
This is pretty old now, needs a rebase, and I think is obviated #1664. Feel free to reopen if you want. |
This is an attempt to reduce the number of schema calls we make to the database, invalidating it once per request.