From 1697888bcb0fb40e573debb5f51b751119c86099 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 17 Jan 2017 11:11:22 +0900 Subject: [PATCH] Fix bug --- src/api/common/add-file-to-drive.ts | 3 +-- src/api/common/get-friends.ts | 3 +-- src/api/endpoints/aggregation/posts/like.js | 3 +-- src/api/endpoints/aggregation/posts/likes.js | 3 +-- src/api/endpoints/aggregation/posts/reply.js | 3 +-- src/api/endpoints/aggregation/posts/repost.js | 3 +-- .../endpoints/aggregation/users/followers.js | 3 +-- .../endpoints/aggregation/users/following.js | 3 +-- src/api/endpoints/aggregation/users/like.js | 3 +-- src/api/endpoints/aggregation/users/post.js | 3 +-- src/api/endpoints/auth/accept.js | 8 ++------ src/api/endpoints/drive.js | 11 +++++------ src/api/endpoints/drive/files.js | 3 +-- src/api/endpoints/drive/files/find.js | 3 +-- src/api/endpoints/drive/files/update.js | 4 +--- src/api/endpoints/drive/folders.js | 3 +-- src/api/endpoints/drive/folders/find.js | 3 +-- src/api/endpoints/drive/folders/update.js | 4 +--- src/api/endpoints/drive/stream.js | 3 +-- src/api/endpoints/following/create.js | 4 ++-- src/api/endpoints/following/delete.js | 6 +++--- src/api/endpoints/i/appdata/set.js | 4 ++-- src/api/endpoints/i/favorites.js | 5 ++--- src/api/endpoints/i/notifications.js | 5 ++--- src/api/endpoints/i/signin_history.js | 5 ++--- src/api/endpoints/i/update.js | 5 ++--- src/api/endpoints/messaging/history.js | 5 ++--- src/api/endpoints/messaging/messages.js | 5 ++--- src/api/endpoints/messaging/messages/create.js | 4 ++-- src/api/endpoints/my/apps.js | 5 ++--- .../endpoints/notifications/mark_as_read.js | 2 +- src/api/endpoints/posts.js | 5 ++--- src/api/endpoints/posts/create.js | 18 ++++++++---------- src/api/endpoints/posts/likes.js | 5 ++--- src/api/endpoints/posts/likes/create.js | 6 +++--- src/api/endpoints/posts/likes/delete.js | 8 ++++---- src/api/endpoints/posts/mentions.js | 5 ++--- src/api/endpoints/posts/replies.js | 5 ++--- src/api/endpoints/posts/reposts.js | 5 ++--- src/api/endpoints/posts/search.js | 8 +++----- src/api/endpoints/posts/timeline.js | 5 ++--- src/api/endpoints/users.js | 5 ++--- src/api/endpoints/users/followers.js | 5 ++--- src/api/endpoints/users/following.js | 5 ++--- src/api/endpoints/users/posts.js | 5 ++--- src/api/endpoints/users/recommendation.js | 5 ++--- src/api/endpoints/users/search.js | 6 ++---- src/api/endpoints/users/search_by_username.js | 3 +-- 48 files changed, 91 insertions(+), 140 deletions(-) diff --git a/src/api/common/add-file-to-drive.ts b/src/api/common/add-file-to-drive.ts index e001216ee..76ca6c913 100644 --- a/src/api/common/add-file-to-drive.ts +++ b/src/api/common/add-file-to-drive.ts @@ -72,8 +72,7 @@ export default ( .find({ user_id: user._id }, { datasize: true, _id: false - }) - .toArray(); + }); // Calculate drive usage (in byte) const usage = files.map(file => file.datasize).reduce((x, y) => x + y, 0); diff --git a/src/api/common/get-friends.ts b/src/api/common/get-friends.ts index 5d50bcdb1..6703382e8 100644 --- a/src/api/common/get-friends.ts +++ b/src/api/common/get-friends.ts @@ -11,8 +11,7 @@ export default async (me: mongodb.ObjectID, includeMe: boolean = true) => { deleted_at: { $exists: false } }, { followee_id: true - }) - .toArray(); + }); // ID list of other users who the I follows const myfollowingIds = myfollowing.map(follow => follow.followee_id); diff --git a/src/api/endpoints/aggregation/posts/like.js b/src/api/endpoints/aggregation/posts/like.js index b82c494ff..b5aa0a21a 100644 --- a/src/api/endpoints/aggregation/posts/like.js +++ b/src/api/endpoints/aggregation/posts/like.js @@ -48,8 +48,7 @@ module.exports = (params) => _id: '$date', count: { $sum: 1 } }} - ]) - .toArray(); + ]); datas.forEach(data => { data.date = data._id; diff --git a/src/api/endpoints/aggregation/posts/likes.js b/src/api/endpoints/aggregation/posts/likes.js index 031724515..2ea22516f 100644 --- a/src/api/endpoints/aggregation/posts/likes.js +++ b/src/api/endpoints/aggregation/posts/likes.js @@ -45,8 +45,7 @@ module.exports = (params) => post_id: false }, { sort: { created_at: -1 } - }) - .toArray(); + }); const graph = []; diff --git a/src/api/endpoints/aggregation/posts/reply.js b/src/api/endpoints/aggregation/posts/reply.js index e578bc6d7..d79ccafb1 100644 --- a/src/api/endpoints/aggregation/posts/reply.js +++ b/src/api/endpoints/aggregation/posts/reply.js @@ -47,8 +47,7 @@ module.exports = (params) => _id: '$date', count: { $sum: 1 } }} - ]) - .toArray(); + ]); datas.forEach(data => { data.date = data._id; diff --git a/src/api/endpoints/aggregation/posts/repost.js b/src/api/endpoints/aggregation/posts/repost.js index 38d63442a..3e4840510 100644 --- a/src/api/endpoints/aggregation/posts/repost.js +++ b/src/api/endpoints/aggregation/posts/repost.js @@ -47,8 +47,7 @@ module.exports = (params) => _id: '$date', count: { $sum: 1 } }} - ]) - .toArray(); + ]); datas.forEach(data => { data.date = data._id; diff --git a/src/api/endpoints/aggregation/users/followers.js b/src/api/endpoints/aggregation/users/followers.js index 16dda0967..f49c2a2fc 100644 --- a/src/api/endpoints/aggregation/users/followers.js +++ b/src/api/endpoints/aggregation/users/followers.js @@ -46,8 +46,7 @@ module.exports = (params) => followee_id: false }, { sort: { created_at: -1 } - }) - .toArray(); + }); const graph = []; diff --git a/src/api/endpoints/aggregation/users/following.js b/src/api/endpoints/aggregation/users/following.js index 7b7448d71..785e5a15c 100644 --- a/src/api/endpoints/aggregation/users/following.js +++ b/src/api/endpoints/aggregation/users/following.js @@ -46,8 +46,7 @@ module.exports = (params) => followee_id: false }, { sort: { created_at: -1 } - }) - .toArray(); + }); const graph = []; diff --git a/src/api/endpoints/aggregation/users/like.js b/src/api/endpoints/aggregation/users/like.js index 830f1f1bb..f5344f6ba 100644 --- a/src/api/endpoints/aggregation/users/like.js +++ b/src/api/endpoints/aggregation/users/like.js @@ -48,8 +48,7 @@ module.exports = (params) => _id: '$date', count: { $sum: 1 } }} - ]) - .toArray(); + ]); datas.forEach(data => { data.date = data._id; diff --git a/src/api/endpoints/aggregation/users/post.js b/src/api/endpoints/aggregation/users/post.js index d75df30f5..f968ff415 100644 --- a/src/api/endpoints/aggregation/users/post.js +++ b/src/api/endpoints/aggregation/users/post.js @@ -70,8 +70,7 @@ module.exports = (params) => count: '$count' }} } } - ]) - .toArray(); + ]); datas.forEach(data => { data.date = data._id; diff --git a/src/api/endpoints/auth/accept.js b/src/api/endpoints/auth/accept.js index 131a0e561..fce4fdc9c 100644 --- a/src/api/endpoints/auth/accept.js +++ b/src/api/endpoints/auth/accept.js @@ -87,12 +87,8 @@ module.exports = (params, user) => } // Update session - await AuthSess.updateOne({ - _id: session._id - }, { - $set: { - user_id: user._id - } + await AuthSess.update(session._id, { + user_id: user._id }); // Response diff --git a/src/api/endpoints/drive.js b/src/api/endpoints/drive.js index 4df4ac33f..f39019e6e 100644 --- a/src/api/endpoints/drive.js +++ b/src/api/endpoints/drive.js @@ -16,12 +16,11 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Fetch all files to calculate drive usage - const files = await DriveFile - .find({ user_id: user._id }, { - datasize: true, - _id: false - }) - .toArray(); + const files = await DriveFile + .find({ user_id: user._id }, { + datasize: true, + _id: false + }); // Calculate drive usage (in byte) const usage = files.map(file => file.datasize).reduce((x, y) => x + y, 0); diff --git a/src/api/endpoints/drive/files.js b/src/api/endpoints/drive/files.js index 7e8ff59f2..512d17db6 100644 --- a/src/api/endpoints/drive/files.js +++ b/src/api/endpoints/drive/files.js @@ -73,8 +73,7 @@ module.exports = (params, user, app) => }, { limit: limit, sort: sort - }) - .toArray(); + }); // Serialize res(await Promise.all(files.map(async file => diff --git a/src/api/endpoints/drive/files/find.js b/src/api/endpoints/drive/files/find.js index e4e4c230d..74f2e4026 100644 --- a/src/api/endpoints/drive/files/find.js +++ b/src/api/endpoints/drive/files/find.js @@ -39,8 +39,7 @@ module.exports = (params, user) => folder_id: folder }, { data: false - }) - .toArray(); + }); // Serialize res(await Promise.all(files.map(async file => diff --git a/src/api/endpoints/drive/files/update.js b/src/api/endpoints/drive/files/update.js index bbcb10b42..13ec30b4f 100644 --- a/src/api/endpoints/drive/files/update.js +++ b/src/api/endpoints/drive/files/update.js @@ -74,9 +74,7 @@ module.exports = (params, user) => } } - DriveFile.updateOne({ _id: file._id }, { - $set: file - }); + DriveFile.update(file._id, file); // Serialize const fileObj = await serialize(file); diff --git a/src/api/endpoints/drive/folders.js b/src/api/endpoints/drive/folders.js index f95a60036..d2a9da280 100644 --- a/src/api/endpoints/drive/folders.js +++ b/src/api/endpoints/drive/folders.js @@ -73,8 +73,7 @@ module.exports = (params, user, app) => }, { limit: limit, sort: sort - }) - .toArray(); + }); // Serialize res(await Promise.all(folders.map(async folder => diff --git a/src/api/endpoints/drive/folders/find.js b/src/api/endpoints/drive/folders/find.js index 01805dc91..9a2faf6d8 100644 --- a/src/api/endpoints/drive/folders/find.js +++ b/src/api/endpoints/drive/folders/find.js @@ -37,8 +37,7 @@ module.exports = (params, user) => name: name, user_id: user._id, parent_id: parentId - }) - .toArray(); + }); // Serialize res(await Promise.all(folders.map(async folder => diff --git a/src/api/endpoints/drive/folders/update.js b/src/api/endpoints/drive/folders/update.js index ff26a09aa..f9aa2998a 100644 --- a/src/api/endpoints/drive/folders/update.js +++ b/src/api/endpoints/drive/folders/update.js @@ -99,9 +99,7 @@ module.exports = (params, user) => } // Update - DriveFolder.updateOne({ _id: folder._id }, { - $set: folder - }); + DriveFolder.update(folder._id, folder); // Serialize const folderObj = await serialize(folder); diff --git a/src/api/endpoints/drive/stream.js b/src/api/endpoints/drive/stream.js index 0f407f559..1d0cbaca2 100644 --- a/src/api/endpoints/drive/stream.js +++ b/src/api/endpoints/drive/stream.js @@ -76,8 +76,7 @@ module.exports = (params, user) => }, { limit: limit, sort: sort - }) - .toArray(); + }); // Serialize res(await Promise.all(files.map(async file => diff --git a/src/api/endpoints/following/create.js b/src/api/endpoints/following/create.js index da714cb18..90a6da983 100644 --- a/src/api/endpoints/following/create.js +++ b/src/api/endpoints/following/create.js @@ -64,14 +64,14 @@ module.exports = (params, user) => res(); // Increment following count - User.updateOne({ _id: follower._id }, { + User.update(follower._id, { $inc: { following_count: 1 } }); // Increment followers count - User.updateOne({ _id: followee._id }, { + User.update({ _id: followee._id }, { $inc: { followers_count: 1 } diff --git a/src/api/endpoints/following/delete.js b/src/api/endpoints/following/delete.js index f1096801b..9bb1b082e 100644 --- a/src/api/endpoints/following/delete.js +++ b/src/api/endpoints/following/delete.js @@ -53,7 +53,7 @@ module.exports = (params, user) => } // Delete following - await Following.updateOne({ + await Following.update({ _id: exist._id }, { $set: { @@ -65,14 +65,14 @@ module.exports = (params, user) => res(); // Decrement following count - User.updateOne({ _id: follower._id }, { + User.update({ _id: follower._id }, { $inc: { following_count: -1 } }); // Decrement followers count - User.updateOne({ _id: followee._id }, { + User.update({ _id: followee._id }, { $inc: { followers_count: -1 } diff --git a/src/api/endpoints/i/appdata/set.js b/src/api/endpoints/i/appdata/set.js index e161a803d..d6506a44f 100644 --- a/src/api/endpoints/i/appdata/set.js +++ b/src/api/endpoints/i/appdata/set.js @@ -29,7 +29,7 @@ module.exports = (params, user, app, isSecure) => data: Object.assign(user.data || {}, JSON.parse(data)) } }; - await User.updateOne({ _id: user._id }, set); + await User.update({ _id: user._id }, set); res(204); } else { const appdata = await Appdata.findOne({ @@ -41,7 +41,7 @@ module.exports = (params, user, app, isSecure) => data: Object.assign((appdata || {}).data || {}, JSON.parse(data)) } }; - await Appdata.updateOne({ + await Appdata.update({ app_id: app._id, user_id: user._id }, Object.assign({ diff --git a/src/api/endpoints/i/favorites.js b/src/api/endpoints/i/favorites.js index e30ea2867..d943bec32 100644 --- a/src/api/endpoints/i/favorites.js +++ b/src/api/endpoints/i/favorites.js @@ -44,14 +44,13 @@ module.exports = (params) => const favorites = await Favorites .find({ user_id: user._id - }, {}, { + }, { limit: limit, skip: offset, sort: { _id: sort == 'asc' ? 1 : -1 } - }) - .toArray(); + }); // Serialize res(await Promise.all(favorites.map(async favorite => diff --git a/src/api/endpoints/i/notifications.js b/src/api/endpoints/i/notifications.js index a28ceb76a..02a2fb179 100644 --- a/src/api/endpoints/i/notifications.js +++ b/src/api/endpoints/i/notifications.js @@ -92,11 +92,10 @@ module.exports = (params, user) => // Issue query const notifications = await Notification - .find(query, {}, { + .find(query, { limit: limit, sort: sort - }) - .toArray(); + }); // Serialize res(await Promise.all(notifications.map(async notification => diff --git a/src/api/endpoints/i/signin_history.js b/src/api/endpoints/i/signin_history.js index 7def8a41e..c373e7b7a 100644 --- a/src/api/endpoints/i/signin_history.js +++ b/src/api/endpoints/i/signin_history.js @@ -59,11 +59,10 @@ module.exports = (params, user) => // Issue query const history = await Signin - .find(query, {}, { + .find(query, { limit: limit, sort: sort - }) - .toArray(); + }); // Serialize res(await Promise.all(history.map(async record => diff --git a/src/api/endpoints/i/update.js b/src/api/endpoints/i/update.js index 3a6b9da90..0306a106e 100644 --- a/src/api/endpoints/i/update.js +++ b/src/api/endpoints/i/update.js @@ -8,6 +8,7 @@ import User from '../../models/user'; import { isValidBirthday } from '../../models/user'; import serialize from '../../serializers/user'; import event from '../../event'; +import config from '../../../conf'; /** * Update myself @@ -73,9 +74,7 @@ module.exports = async (params, user, _, isSecure) => user.banner_id = new mongo.ObjectID(banner); } - await User.updateOne({ _id: user._id }, { - $set: user - }); + await User.update(user._id, user); // Serialize const iObj = await serialize(user, user, { diff --git a/src/api/endpoints/messaging/history.js b/src/api/endpoints/messaging/history.js index dafb38fd1..e6e6ac87b 100644 --- a/src/api/endpoints/messaging/history.js +++ b/src/api/endpoints/messaging/history.js @@ -34,13 +34,12 @@ module.exports = (params, user) => const history = await History .find({ user_id: user._id - }, {}, { + }, { limit: limit, sort: { updated_at: -1 } - }) - .toArray(); + }); // Serialize res(await Promise.all(history.map(async h => diff --git a/src/api/endpoints/messaging/messages.js b/src/api/endpoints/messaging/messages.js index 12bd13597..9440e2b3a 100644 --- a/src/api/endpoints/messaging/messages.js +++ b/src/api/endpoints/messaging/messages.js @@ -90,11 +90,10 @@ module.exports = (params, user) => // Issue query const messages = await Message - .find(query, {}, { + .find(query, { limit: limit, sort: sort - }) - .toArray(); + }); // Serialize res(await Promise.all(messages.map(async message => diff --git a/src/api/endpoints/messaging/messages/create.js b/src/api/endpoints/messaging/messages/create.js index 33634a614..1cd02cfc5 100644 --- a/src/api/endpoints/messaging/messages/create.js +++ b/src/api/endpoints/messaging/messages/create.js @@ -125,7 +125,7 @@ module.exports = (params, user) => } // 履歴作成(自分) - History.updateOne({ + History.update({ user_id: user._id, partner: recipient._id }, { @@ -138,7 +138,7 @@ module.exports = (params, user) => }); // 履歴作成(相手) - History.updateOne({ + History.update({ user_id: recipient._id, partner: user._id }, { diff --git a/src/api/endpoints/my/apps.js b/src/api/endpoints/my/apps.js index d23bc38b1..3745a92e0 100644 --- a/src/api/endpoints/my/apps.js +++ b/src/api/endpoints/my/apps.js @@ -44,14 +44,13 @@ module.exports = (params, user) => // Execute query const apps = await App - .find(query, {}, { + .find(query, { limit: limit, skip: offset, sort: { created_at: -1 } - }) - .toArray(); + }); // Reply res(await Promise.all(apps.map(async app => diff --git a/src/api/endpoints/notifications/mark_as_read.js b/src/api/endpoints/notifications/mark_as_read.js index 16eb2009a..855596a86 100644 --- a/src/api/endpoints/notifications/mark_as_read.js +++ b/src/api/endpoints/notifications/mark_as_read.js @@ -37,7 +37,7 @@ module.exports = (params, user) => // Update notification.is_read = true; - Notification.updateOne({ _id: notification._id }, { + Notification.update({ _id: notification._id }, { $set: { is_read: true } diff --git a/src/api/endpoints/posts.js b/src/api/endpoints/posts.js index 05fc871ec..0428b400b 100644 --- a/src/api/endpoints/posts.js +++ b/src/api/endpoints/posts.js @@ -54,11 +54,10 @@ module.exports = (params) => // Issue query const posts = await Post - .find(query, {}, { + .find(query, { limit: limit, sort: sort - }) - .toArray(); + }); // Serialize res(await Promise.all(posts.map(async post => await serialize(post)))); diff --git a/src/api/endpoints/posts/create.js b/src/api/endpoints/posts/create.js index 694e6fc82..c3291bc72 100644 --- a/src/api/endpoints/posts/create.js +++ b/src/api/endpoints/posts/create.js @@ -13,6 +13,7 @@ import serialize from '../../serializers/post'; import createFile from '../../common/add-file-to-drive'; import notify from '../../common/notify'; import event from '../../event'; +import config from '../../../conf'; /** * 最大文字数 @@ -103,7 +104,7 @@ module.exports = (params, user, app) => // Fetch recently post const latestPost = await Post.findOne({ user_id: user._id - }, {}, { + }, { sort: { _id: -1 } @@ -152,7 +153,7 @@ module.exports = (params, user, app) => } // 投稿を作成 - const inserted = await Post.insert({ + const post = await Post.insert({ created_at: new Date(), media_ids: media ? files.map(file => file._id) : undefined, reply_to_id: replyTo ? replyTo._id : undefined, @@ -162,8 +163,6 @@ module.exports = (params, user, app) => app_id: app ? app._id : null }); - const post = inserted.ops[0]; - // Serialize const postObj = await serialize(post); @@ -200,15 +199,14 @@ module.exports = (params, user, app) => }, { follower_id: true, _id: false - }) - .toArray(); + }); // Publish event to followers stream followers.forEach(following => event(following.follower_id, 'post', postObj)); // Increment my posts count - User.updateOne({ _id: user._id }, { + User.update({ _id: user._id }, { $inc: { posts_count: 1 } @@ -217,7 +215,7 @@ module.exports = (params, user, app) => // If has in reply to post if (replyTo) { // Increment replies count - Post.updateOne({ _id: replyTo._id }, { + Post.update({ _id: replyTo._id }, { $inc: { replies_count: 1 } @@ -262,7 +260,7 @@ module.exports = (params, user, app) => if (!existRepost) { // Update repostee status - Post.updateOne({ _id: repost._id }, { + Post.update({ _id: repost._id }, { $inc: { repost_count: 1 } @@ -336,7 +334,7 @@ module.exports = (params, user, app) => // Append mentions data if (mentions.length > 0) { - Post.updateOne({ _id: post._id }, { + Post.update({ _id: post._id }, { $set: { mentions: mentions } diff --git a/src/api/endpoints/posts/likes.js b/src/api/endpoints/posts/likes.js index 4778189fc..6d3ab866b 100644 --- a/src/api/endpoints/posts/likes.js +++ b/src/api/endpoints/posts/likes.js @@ -62,14 +62,13 @@ module.exports = (params, user) => .find({ post_id: post._id, deleted_at: { $exists: false } - }, {}, { + }, { limit: limit, skip: offset, sort: { _id: sort == 'asc' ? 1 : -1 } - }) - .toArray(); + }); // Serialize res(await Promise.all(likes.map(async like => diff --git a/src/api/endpoints/posts/likes/create.js b/src/api/endpoints/posts/likes/create.js index eb35c1e4b..73054be87 100644 --- a/src/api/endpoints/posts/likes/create.js +++ b/src/api/endpoints/posts/likes/create.js @@ -66,21 +66,21 @@ module.exports = (params, user) => res(); // Increment likes count - Post.updateOne({ _id: post._id }, { + Post.update({ _id: post._id }, { $inc: { likes_count: 1 } }); // Increment user likes count - User.updateOne({ _id: user._id }, { + User.update({ _id: user._id }, { $inc: { likes_count: 1 } }); // Increment user liked count - User.updateOne({ _id: post.user_id }, { + User.update({ _id: post.user_id }, { $inc: { liked_count: 1 } diff --git a/src/api/endpoints/posts/likes/delete.js b/src/api/endpoints/posts/likes/delete.js index b60df63af..b5b7e5177 100644 --- a/src/api/endpoints/posts/likes/delete.js +++ b/src/api/endpoints/posts/likes/delete.js @@ -46,7 +46,7 @@ module.exports = (params, user) => } // Delete like - await Like.updateOne({ + await Like.update({ _id: exist._id }, { $set: { @@ -58,21 +58,21 @@ module.exports = (params, user) => res(); // Decrement likes count - Post.updateOne({ _id: post._id }, { + Post.update({ _id: post._id }, { $inc: { likes_count: -1 } }); // Decrement user likes count - User.updateOne({ _id: user._id }, { + User.update({ _id: user._id }, { $inc: { likes_count: -1 } }); // Decrement user liked count - User.updateOne({ _id: post.user_id }, { + User.update({ _id: post.user_id }, { $inc: { liked_count: -1 } diff --git a/src/api/endpoints/posts/mentions.js b/src/api/endpoints/posts/mentions.js index 6358e1f4a..dbb69bd5a 100644 --- a/src/api/endpoints/posts/mentions.js +++ b/src/api/endpoints/posts/mentions.js @@ -72,11 +72,10 @@ module.exports = (params, user) => // Issue query const mentions = await Post - .find(query, {}, { + .find(query, { limit: limit, sort: sort - }) - .toArray(); + }); // Serialize res(await Promise.all(mentions.map(async mention => diff --git a/src/api/endpoints/posts/replies.js b/src/api/endpoints/posts/replies.js index 5eab6f896..5ce1133e0 100644 --- a/src/api/endpoints/posts/replies.js +++ b/src/api/endpoints/posts/replies.js @@ -58,14 +58,13 @@ module.exports = (params, user) => // Issue query const replies = await Post - .find({ reply_to_id: post._id }, {}, { + .find({ reply_to_id: post._id }, { limit: limit, skip: offset, sort: { _id: sort == 'asc' ? 1 : -1 } - }) - .toArray(); + }); // Serialize res(await Promise.all(replies.map(async post => diff --git a/src/api/endpoints/posts/reposts.js b/src/api/endpoints/posts/reposts.js index 8b418a682..a118ca6fb 100644 --- a/src/api/endpoints/posts/reposts.js +++ b/src/api/endpoints/posts/reposts.js @@ -73,11 +73,10 @@ module.exports = (params, user) => // Issue query const reposts = await Post - .find(query, {}, { + .find(query, { limit: limit, sort: sort - }) - .toArray(); + }); // Serialize res(await Promise.all(reposts.map(async post => diff --git a/src/api/endpoints/posts/search.js b/src/api/endpoints/posts/search.js index 0f214ef7a..239517b99 100644 --- a/src/api/endpoints/posts/search.js +++ b/src/api/endpoints/posts/search.js @@ -65,8 +65,7 @@ async function byNative(res, rej, me, query, offset, max) { }, limit: max, skip: offset - }) - .toArray(); + }); // Serialize res(await Promise.all(posts.map(async post => @@ -120,12 +119,11 @@ async function byElasticsearch(res, rej, me, query, offset, max) { _id: { $in: hits } - }, {}, { + }, { sort: { _id: -1 } - }) - .toArray(); + }); posts.map(post => { post._highlight = response.hits.hits.filter(hit => post._id.equals(hit._id))[0].highlight.text[0]; diff --git a/src/api/endpoints/posts/timeline.js b/src/api/endpoints/posts/timeline.js index 489542da7..626f828ef 100644 --- a/src/api/endpoints/posts/timeline.js +++ b/src/api/endpoints/posts/timeline.js @@ -65,11 +65,10 @@ module.exports = (params, user, app) => // Issue query const timeline = await Post - .find(query, {}, { + .find(query, { limit: limit, sort: sort - }) - .toArray(); + }); // Serialize res(await Promise.all(timeline.map(async post => diff --git a/src/api/endpoints/users.js b/src/api/endpoints/users.js index cd40cdf4e..1c6024e3e 100644 --- a/src/api/endpoints/users.js +++ b/src/api/endpoints/users.js @@ -55,11 +55,10 @@ module.exports = (params, me) => // Issue query const users = await User - .find(query, {}, { + .find(query, { limit: limit, sort: sort - }) - .toArray(); + }); // Serialize res(await Promise.all(users.map(async user => diff --git a/src/api/endpoints/users/followers.js b/src/api/endpoints/users/followers.js index 303f55e45..ac6136123 100644 --- a/src/api/endpoints/users/followers.js +++ b/src/api/endpoints/users/followers.js @@ -78,11 +78,10 @@ module.exports = (params, me) => // Get followers const following = await Following - .find(query, {}, { + .find(query, { limit: limit + 1, sort: { _id: -1 } - }) - .toArray(); + }); // 「次のページ」があるかどうか const inStock = following.length === limit + 1; diff --git a/src/api/endpoints/users/following.js b/src/api/endpoints/users/following.js index ec3954563..c1266b1d1 100644 --- a/src/api/endpoints/users/following.js +++ b/src/api/endpoints/users/following.js @@ -78,11 +78,10 @@ module.exports = (params, me) => // Get followers const following = await Following - .find(query, {}, { + .find(query, { limit: limit + 1, sort: { _id: -1 } - }) - .toArray(); + }); // 「次のページ」があるかどうか const inStock = following.length === limit + 1; diff --git a/src/api/endpoints/users/posts.js b/src/api/endpoints/users/posts.js index 1b8dfe031..8902cc314 100644 --- a/src/api/endpoints/users/posts.js +++ b/src/api/endpoints/users/posts.js @@ -111,11 +111,10 @@ module.exports = (params, me) => // Issue query const posts = await Post - .find(query, {}, { + .find(query, { limit: limit, sort: sort - }) - .toArray(); + }); // Serialize res(await Promise.all(posts.map(async (post) => diff --git a/src/api/endpoints/users/recommendation.js b/src/api/endpoints/users/recommendation.js index 9daab0ec5..d4c33c37a 100644 --- a/src/api/endpoints/users/recommendation.js +++ b/src/api/endpoints/users/recommendation.js @@ -46,14 +46,13 @@ module.exports = (params, me) => _id: { $nin: followingIds } - }, {}, { + }, { limit: limit, skip: offset, sort: { followers_count: -1 } - }) - .toArray(); + }); // Serialize res(await Promise.all(users.map(async user => diff --git a/src/api/endpoints/users/search.js b/src/api/endpoints/users/search.js index 3a3fe677d..f8b2eccec 100644 --- a/src/api/endpoints/users/search.js +++ b/src/api/endpoints/users/search.js @@ -63,8 +63,7 @@ async function byNative(res, rej, me, query, offset, max) { }, { name: new RegExp(escapedQuery) }] - }) - .toArray(); + }); // Serialize res(await Promise.all(users.map(async user => @@ -106,8 +105,7 @@ async function byElasticsearch(res, rej, me, query, offset, max) { _id: { $in: hits } - }) - .toArray(); + }); // Serialize res(await Promise.all(users.map(async user => diff --git a/src/api/endpoints/users/search_by_username.js b/src/api/endpoints/users/search_by_username.js index 9e3efbd85..2f19df3c8 100644 --- a/src/api/endpoints/users/search_by_username.js +++ b/src/api/endpoints/users/search_by_username.js @@ -56,8 +56,7 @@ module.exports = (params, me) => }, { limit: limit, skip: offset - }) - .toArray(); + }); // Serialize res(await Promise.all(users.map(async user =>