|
1 | 1 | const express = require('express'); |
2 | 2 | const multer = require('multer'); |
3 | 3 | const moment = require('moment'); |
| 4 | +const { getPostsByPoster, getPostsByEmpathy } = require('@/api/post'); |
4 | 5 | const database = require('@/database'); |
5 | 6 | const util = require('@/util'); |
6 | 7 | const { getUserFriendPIDs } = util; |
7 | 8 | const { POST } = require('@/models/post'); |
8 | 9 | const { SETTINGS } = require('@/models/settings'); |
9 | | -const redis = require('@/redisCache'); |
10 | | -const { config } = require('@/config'); |
11 | 10 | const { logger } = require('@/logger'); |
12 | 11 | const router = express.Router(); |
13 | 12 | const upload = multer({ dest: 'uploads/' }); |
@@ -148,11 +147,7 @@ async function userPage(req, res, userID) { |
148 | 147 | } |
149 | 148 |
|
150 | 149 | const userSettings = await database.getUserSettings(userID); |
151 | | - let posts = JSON.parse(await redis.getValue(`${userID}-user_page_posts`)); |
152 | | - if (!posts) { |
153 | | - posts = await database.getNumberUserPostsByID(userID, config.postLimit, res.locals.moderator); |
154 | | - await redis.setValue(`${userID}_user_page_posts`, JSON.stringify(posts), 60 * 60 * 1); |
155 | | - } |
| 150 | + const posts = (await getPostsByPoster(req.tokens, userID, 0))?.items; |
156 | 151 |
|
157 | 152 | const numPosts = await database.getTotalPostsByUserID(userID); |
158 | 153 | const communityMap = await util.getCommunityHash(); |
@@ -215,7 +210,7 @@ async function userRelations(req, res, userID) { |
215 | 210 | let selection; |
216 | 211 |
|
217 | 212 | if (req.params.type === 'yeahs') { |
218 | | - const posts = await POST.find({ yeahs: userID, removed: false }).sort({ created_at: -1 }).limit(config.postLimit); |
| 213 | + const posts = (await getPostsByEmpathy(req.tokens, userID, 0))?.items; |
219 | 214 | const communityMap = await util.getCommunityHash(); |
220 | 215 | const bundle = { |
221 | 216 | posts, |
@@ -304,7 +299,7 @@ async function morePosts(req, res, userID) { |
304 | 299 | if (!offset) { |
305 | 300 | offset = 0; |
306 | 301 | } |
307 | | - const posts = await database.getUserPostsOffset(userID, config.postLimit, offset); |
| 302 | + const posts = (await getPostsByPoster(req.tokens, userID, offset))?.items; |
308 | 303 |
|
309 | 304 | const bundle = { |
310 | 305 | posts, |
@@ -334,7 +329,7 @@ async function moreYeahPosts(req, res, userID) { |
334 | 329 | if (!offset) { |
335 | 330 | offset = 0; |
336 | 331 | } |
337 | | - const posts = await POST.find({ yeahs: userID, removed: false }).sort({ created_at: -1 }).skip(offset).limit(config.postLimit); |
| 332 | + const posts = (await getPostsByEmpathy(req.tokens, userID, offset))?.items; |
338 | 333 |
|
339 | 334 | const bundle = { |
340 | 335 | posts: posts, |
|
0 commit comments