[WIP] Reduce initial user query load #6927
+118
−70
BerkeleyTrue
commented
server/component-passport.js
| + return; | ||
| + } | ||
| + | ||
| + this.app.middleware('session:after', passport.session()); | ||
| + | ||
| + // Serialization and deserialization is only required if passport session is | ||
| + // enabled | ||
| + | ||
| + passport.serializeUser((user, done) => { | ||
| + done(null, user.id); | ||
| + }); | ||
| + | ||
| + passport.deserializeUser((id, done) => { | ||
| + | ||
| + this.userModel.findById(id, { fields }, (err, user) => { | ||
| + if (err || !user) { |
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
|
server/component-passport.js
| + done(null, user.id); | ||
| + }); | ||
| + | ||
| + passport.deserializeUser((id, done) => { | ||
| + | ||
| + this.userModel.findById(id, { fields }, (err, user) => { | ||
| + if (err || !user) { | ||
| + return done(err, user); | ||
| + } | ||
| + this.app.dataSources.db.connector | ||
| + .collection('user') | ||
| + .aggregate([ | ||
| + { $match: { _id: user.id } }, | ||
| + { $project: { points: { $size: '$progressTimestamps' } } } | ||
| + ], function(err, { points = 1 } = {}) { | ||
| + if (err) { return done(err); } |
|
Use MongoDB pipeline aggregation to return user brownie points. This is done in such a way that we can later change progressTimestamps to scaled brownie points
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Refactor passport to own file