Closed ridersshare closed 9 months ago
Just adding some context. This update was taking ~30 seconds on our database and was running multiple times (once for each container) totally hosing our UX/delaying database actions etc. I wasn't seeing/understanding why it such a broad query so this seemed like a good solution. Maybe someone closer to the project will have some other ideas though :)
@filipenevola just circling back to this since Storyteller reminded :D
We discussed using this mongo selector code:
{ $or: [{ "status.online": true }, { "status.idle": { $exists: true } }, { "status.lastActivity": { $exists: true } }] }
Instead of: { } 😁
The goal being, don't perform an update on all users, only those with status.online = true
or non-null status.idle
or status.lastActivity
fields.
But I'm concerned this could cause DB performance issues for other people if the proper indexes aren't set. I experimented on our server:
Test Query:
db.users.find({ $or: [{ "status.online": true }, { "status.idle": { $exists: true } }, { "status.lastActivity": { $exists: true } }] }).limit(100)
Without indexes this takes = 33 seconds, but with these three set:
db.useres.createIndex({"status.online":1}) db.useres.createIndex({"status.idle":1}) db.useres.createIndex({"status.lastActivity":1})
That test query takes a 1/10th of a second.
Is it that expected/typical of a meteor package and is there a particular place in the code indexing should be handled?
Alternatively, maybe the whole selector should be optional:
Line 138 could be (something like this?):
selector = Meteor.settings.packages['mizzao:user-status'].startupQuery || {};
Then I could set this query in our settings file and create the indexes manually/elsewhere.
I think both options are valid:
Both could be optional or have options to disable each of them.
closing this in favor of https://github.com/Meteor-Community-Packages/meteor-user-status/pull/178
Prevent updating all users at startup unnecessarily.