full app
This commit is contained in:
@@ -12,7 +12,7 @@ async function attachPostEngagementFields(posts, viewerId) {
|
||||
const postIds = posts.map((p) => p._id)
|
||||
const authorIds = [...new Set(posts.map((p) => String(p.user_id)))]
|
||||
|
||||
const [bookmarkAgg, sendAgg, shareAgg, viewAgg, authorDocs, userBookmarks, userFollows, activeStories] = await Promise.all([
|
||||
const [bookmarkAgg, sendAgg, shareAgg, viewAgg, offerAgg, authorDocs, userBookmarks, userFollows, activeStories] = await Promise.all([
|
||||
PostBookmarkModel.aggregate([
|
||||
{ $match: { postId: { $in: postIds } } },
|
||||
{ $group: { _id: '$postId', count: { $sum: 1 } } },
|
||||
@@ -35,6 +35,16 @@ async function attachPostEngagementFields(posts, viewerId) {
|
||||
},
|
||||
{ $group: { _id: '$targetId', count: { $sum: 1 } } },
|
||||
]),
|
||||
ExploreInteractionModel.aggregate([
|
||||
{
|
||||
$match: {
|
||||
targetType: 'post',
|
||||
targetId: { $in: postIds },
|
||||
action: 'offer',
|
||||
},
|
||||
},
|
||||
{ $group: { _id: '$targetId', count: { $sum: 1 } } },
|
||||
]),
|
||||
UserModel.find({ _id: { $in: authorIds } })
|
||||
.select('_id allow_save_posts')
|
||||
.lean(),
|
||||
@@ -68,6 +78,9 @@ async function attachPostEngagementFields(posts, viewerId) {
|
||||
const viewsMap = Object.fromEntries(
|
||||
viewAgg.map((v) => [String(v._id), v.count])
|
||||
)
|
||||
const offersMap = Object.fromEntries(
|
||||
offerAgg.map((o) => [String(o._id), o.count])
|
||||
)
|
||||
const allowSaveMap = Object.fromEntries(
|
||||
authorDocs.map((u) => [String(u._id), u.allow_save_posts !== false])
|
||||
)
|
||||
@@ -95,6 +108,7 @@ async function attachPostEngagementFields(posts, viewerId) {
|
||||
sendsCount: sendsMap[String(post._id)] || 0,
|
||||
sharesCount: sharesMap[String(post._id)] || 0,
|
||||
viewsCount: viewsMap[String(post._id)] || 0,
|
||||
offersCount: offersMap[String(post._id)] || 0,
|
||||
author_allow_save: allowSaveMap[String(post.user_id)] !== false,
|
||||
is_saved: savedSet.has(String(post._id)),
|
||||
is_following: followSet.has(String(post.user_id)),
|
||||
|
||||
Reference in New Issue
Block a user