[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

@ -25,6 +25,10 @@ module.exports = (params) =>
// Lookup user
const user = await User.findOne({
_id: new mongo.ObjectID(userId)
}, {
fields: {
_id: true
}
});
if (user === null) {

View file

@ -25,6 +25,10 @@ module.exports = (params) =>
// Lookup user
const user = await User.findOne({
_id: new mongo.ObjectID(userId)
}, {
fields: {
_id: true
}
});
if (user === null) {

View file

@ -25,6 +25,10 @@ module.exports = (params) =>
// Lookup user
const user = await User.findOne({
_id: new mongo.ObjectID(userId)
}, {
fields: {
_id: true
}
});
if (user === null) {

View file

@ -25,6 +25,10 @@ module.exports = (params) =>
// Lookup user
const user = await User.findOne({
_id: new mongo.ObjectID(userId)
}, {
fields: {
_id: true
}
});
if (user === null) {

View file

@ -41,6 +41,11 @@ module.exports = (params, user) =>
// Get followee
const followee = await User.findOne({
_id: new mongo.ObjectID(userId)
}, {
fields: {
data: false,
profile: false
}
});
if (followee === null) {

View file

@ -40,6 +40,11 @@ module.exports = (params, user) =>
// Get followee
const followee = await User.findOne({
_id: new mongo.ObjectID(userId)
}, {
fields: {
data: false,
profile: false
}
});
if (followee === null) {

View file

@ -25,6 +25,10 @@ module.exports = (params, user) =>
if (recipient !== undefined && recipient !== null) {
recipient = await User.findOne({
_id: new mongo.ObjectID(recipient)
}, {
fields: {
_id: true
}
});
if (recipient === null) {

View file

@ -33,6 +33,10 @@ module.exports = (params, user) =>
if (recipient !== undefined && recipient !== null) {
recipient = await User.findOne({
_id: new mongo.ObjectID(recipient)
}, {
fields: {
_id: true
}
});
if (recipient === null) {

View file

@ -47,6 +47,10 @@ module.exports = (params, me) =>
// Lookup user
const user = await User.findOne({
_id: new mongo.ObjectID(userId)
}, {
fields: {
_id: true
}
});
if (user === null) {

View file

@ -47,6 +47,10 @@ module.exports = (params, me) =>
// Lookup user
const user = await User.findOne({
_id: new mongo.ObjectID(userId)
}, {
fields: {
_id: true
}
});
if (user === null) {

View file

@ -67,10 +67,16 @@ module.exports = (params, me) =>
return rej('cannot set since_id and max_id');
}
const q = userId != null
? { _id: new mongo.ObjectID(userId) }
: { username_lower: username.toLowerCase() } ;
// Lookup user
const user = userId !== null
? await User.findOne({ _id: new mongo.ObjectID(userId) })
: await User.findOne({ username_lower: username.toLowerCase() });
const user = await User.findOne(q, {
fields: {
_id: true
}
});
if (user === null) {
return rej('user not found');

View file

@ -38,10 +38,16 @@ module.exports = (params, me) =>
return rej('incorrect user_id');
}
const q = userId != null
? { _id: new mongo.ObjectID(userId) }
: { username_lower: username.toLowerCase() } ;
// Lookup user
const user = userId !== null
? await User.findOne({ _id: new mongo.ObjectID(userId) })
: await User.findOne({ username_lower: username.toLowerCase() });
const user = await User.findOne(q, {
fields: {
data: false
}
});
if (user === null) {
return rej('user not found');

View file

@ -15,6 +15,11 @@ export default async (req: express.Request, res: express.Response) => {
// Fetch user
const user = await User.findOne({
username_lower: username.toLowerCase()
}, {
fields: {
data: false,
profile: false
}
});
if (user === null) {

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);
}