From 6a7bc1c5fbd9f08d295f20b47fc4c337a4aa56f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 24 Jun 2019 17:26:28 -0400 Subject: [PATCH] fix: on new post add it to cid::uid::pids --- src/posts/create.js | 12 +++++------- src/user/posts.js | 9 ++++++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/posts/create.js b/src/posts/create.js index 3aa0753e7f..1b2ec02acf 100644 --- a/src/posts/create.js +++ b/src/posts/create.js @@ -64,6 +64,10 @@ module.exports = function (Posts) { db.setObject('post:' + postData.pid, postData, next); }, function (next) { + topics.getTopicFields(tid, ['cid', 'pinned'], next); + }, + function (topicData, next) { + postData.cid = topicData.cid; async.parallel([ function (next) { user.onNewPostMade(postData, next); @@ -72,13 +76,7 @@ module.exports = function (Posts) { topics.onNewPostMade(postData, next); }, function (next) { - topics.getTopicFields(tid, ['cid', 'pinned'], function (err, topicData) { - if (err) { - return next(err); - } - postData.cid = topicData.cid; - categories.onNewPostMade(topicData.cid, topicData.pinned, postData, next); - }); + categories.onNewPostMade(topicData.cid, topicData.pinned, postData, next); }, function (next) { groups.onNewPostMade(postData, next); diff --git a/src/user/posts.js b/src/user/posts.js index d8b7f999f6..19c3a6b5f5 100644 --- a/src/user/posts.js +++ b/src/user/posts.js @@ -69,7 +69,7 @@ module.exports = function (User) { User.onNewPostMade = function (postData, callback) { async.series([ function (next) { - User.addPostIdToUser(postData.uid, postData.pid, postData.timestamp, next); + User.addPostIdToUser(postData, next); }, function (next) { User.incrementUserPostCountBy(postData.uid, 1, next); @@ -83,8 +83,11 @@ module.exports = function (User) { ], callback); }; - User.addPostIdToUser = function (uid, pid, timestamp, callback) { - db.sortedSetAdd('uid:' + uid + ':posts', timestamp, pid, callback); + User.addPostIdToUser = function (postData, callback) { + db.sortedSetsAdd([ + 'uid:' + postData.uid + ':posts', + 'cid:' + postData.cid + ':uid:' + postData.uid + ':pids', + ], postData.timestamp, postData.pid, callback); }; User.incrementUserPostCountBy = function (uid, value, callback) {