Skip to content

[WIP] Reduce initial user query load #6927

Open
wants to merge 1 commit into from

2 participants

@BerkeleyTrue

Refactor passport to own file

@BerkeleyTrue BerkeleyTrue Reduce initial user query load
Refactor passport to own file
3767f8d
@BerkeleyTrue BerkeleyTrue added blocked QA and removed blocked labels
@BerkeleyTrue BerkeleyTrue commented on the diff
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) {

add field filter to exclude potentially large user properties

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@BerkeleyTrue BerkeleyTrue commented on the diff
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
@BerkeleyTrue BerkeleyTrue added blocked and removed QA labels
@bugron

@BerkeleyTrue what's the status of this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.