[Server] Some performance improvements

This commit is contained in:
syuilo
2017-02-22 13:08:33 +09:00
parent e52965a923
commit 1f88c4d40c
14 changed files with 74 additions and 8 deletions

View File

@ -34,15 +34,22 @@ export default (
let _user: any;
const fields = opts.detail ? {
data: false
} : {
data: false,
profile: false
};
// Populate the user if 'user' is ID
if (mongo.ObjectID.prototype.isPrototypeOf(user)) {
_user = await User.findOne({
_id: user
});
}, { fields });
} else if (typeof user === 'string') {
_user = await User.findOne({
_id: new mongo.ObjectID(user)
});
}, { fields });
} else {
_user = deepcopy(user);
}