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
Meteor.users.find() in core without field specifier could be a performance issue #10469
Comments
The occurrences of Limiting these to certain fields could be a breaking change for some users. I think a way could be found of specifying which fields are required (or not required) by these callbacks (maybe similar to the undocumented Either that or the documentation at "Custom data about users" should include a warning about the full user object being retrieved from the db upon every login/logout/refresh so the developer can make an informed decision about keeping large data sets in a separate collection. Note that the full user data retrieved for the _successfulLogout(connection, userId) {
if (Object.keys(this._onLogoutHook.callbacks).length===0) {
return;
}
const user = userId && this.users.findOne(userId);
this._onLogoutHook.each(callback => {
callback({ user, connection });
return true;
});
}; But I'm not sure if |
Here's more:
These would need Ideally |
I disagree that this impacts few - I suspect that most Meteor apps store some amount of data on the user object so this will be a minor performance bug for many and a major performance bug to few apps. Following a short discussion in the forum I am keen to create a PR to fix this. However, doing it properly would require some new public API which would be backwards compatible but would need to be documented and maintained. So before I do that I would like to gauge whether or not new API would be accepted and if so, what format it should take. Therefore I would be grateful if @klaussner or @benjamn could comment before I start. Proposed APIThe new API would involve an optional additional parameter to If no parameter is specified for Callback default fieldsHowever, for the callbacks I suggest that by default the fields are limited to the standard fields A solution to this could be to allow the user to opt-in to limited fields on the callback handlers, but this opt-in would require additional API. For example, a user could set Additional parameter formatThere are various options for the format of the additional parameter:
Options 1 and 2 are more consistent with standard mongo parameters. Option 1 is compatible with the user-extra package by @mitar and feature request #82. Option 3 is compatible with the userCache package by @msavin. Or it may be necessary to support at least both of options 1 and 3 to maintain compatibility with those other packages. Thoughts? Optional logging to find unlimited queriesI would also like to add some optional logging to help the user identify code or packages which call (e.g.) This could simply be Tests and documentationMy PR would include updated tests and documentation. [edit: typos] |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Still relevant. |
I'm still keen to create a PR for this but would like guidance on the new API. @filipenevola, would you be able to get someone to respond to my comment above? |
@wildhart I agree with your ideas, go ahead with a PR. It's very important to keep backward compatible (100%). |
@filipenevola I think the question is which of possible APIs to use here, see options 1-3 above. |
I prefer |
Thanks @fillipenevola, I'll get started on a PR... |
…ing, no new api)
including new Meteor.user() options parameter and Accounts.config({defaultFieldSelector...})
Limit fetching full user objects (performance) Fixes #10469
PR #10818 is merged. It will be available on 1.10 |
Meteor core contains several instances of
Meteor.users().find()
andMeteor.users().findOne()
without a field specifier in situations where only certain fields are required.If a developer stores custom data on the
Meteor.users()
collection (as recommended in the Guide) then this will cause unnecessary data transfer between the db server and the meteor server. This could be significant if lots of custom data is stored in the Meteor.users collection.These examples definitely only need specific fields:
These may need the full user object to pass to the callbacks, I'm not sure:
This one has a definite error by omitting the
fields:
prefix:There will probably be other instances in other files/packages - I haven't done a thorough search.
The text was updated successfully, but these errors were encountered: