diff options
| author | otofune <otofune@gmail.com> | 2017-11-06 15:18:45 +0900 |
|---|---|---|
| committer | otofune <otofune@gmail.com> | 2017-11-06 15:18:45 +0900 |
| commit | 18b1ef29adc6166c2b1a327b378c3e159a18b80c (patch) | |
| tree | 7d8f0b8d09d687856e22c0d6d84dbd18b50b6e7a /src/api/endpoints/posts/timeline.ts | |
| parent | support GridFS (diff) | |
| download | sharkey-18b1ef29adc6166c2b1a327b378c3e159a18b80c.tar.gz sharkey-18b1ef29adc6166c2b1a327b378c3e159a18b80c.tar.bz2 sharkey-18b1ef29adc6166c2b1a327b378c3e159a18b80c.zip | |
migration to GridFS's DriveFile
Diffstat (limited to 'src/api/endpoints/posts/timeline.ts')
| -rw-r--r-- | src/api/endpoints/posts/timeline.ts | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/api/endpoints/posts/timeline.ts b/src/api/endpoints/posts/timeline.ts index aa5aff5ba5..496de62b69 100644 --- a/src/api/endpoints/posts/timeline.ts +++ b/src/api/endpoints/posts/timeline.ts @@ -2,6 +2,7 @@ * Module dependencies */ import $ from 'cafy'; +import rap from '@prezzemolo/rap'; import Post from '../../models/post'; import ChannelWatching from '../../models/channel-watching'; import getFriends from '../../common/get-friends'; @@ -33,14 +34,15 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => { return rej('cannot set since_id and max_id'); } - // ID list of the user itself and other users who the user follows - const followingIds = await getFriends(user._id); - - // Watchしているチャンネルを取得 - const watches = await ChannelWatching.find({ - user_id: user._id, - // 削除されたドキュメントは除く - deleted_at: { $exists: false } + const { followingIds, watchChannelIds } = await rap({ + // ID list of the user itself and other users who the user follows + followingIds: getFriends(user._id), + // Watchしているチャンネルを取得 + watchChannelIds: ChannelWatching.find({ + user_id: user._id, + // 削除されたドキュメントは除く + deleted_at: { $exists: false } + }).then(watches => watches.map(w => w.channel_id)) }); //#region Construct query @@ -65,7 +67,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => { }, { // Watchしているチャンネルへの投稿 channel_id: { - $in: watches.map(w => w.channel_id) + $in: watchChannelIds } }] } as any; @@ -90,7 +92,5 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => { }); // Serialize - res(await Promise.all(timeline.map(async post => - await serialize(post, user) - ))); + res(Promise.all(timeline.map(post => serialize(post, user)))); }); |