Node.js based forum software built for the modern web
fix: controversial posts/bests posts not showing anything
Barış Soner Uşaklı079c487dcb97
diff --git a/src/categories/recentreplies.js b/src/categories/recentreplies.jsindex 935ef80642..0e5618b4fe 100644--- a/src/categories/recentreplies.js+++ b/src/categories/recentreplies.js@@ -176,7 +176,7 @@ module.exports = function (Categories) {bulkRemove.push([`cid:${oldCid}:uid:${post.uid}:pids`, post.pid]);bulkRemove.push([`cid:${oldCid}:uid:${post.uid}:pids:votes`, post.pid]);bulkAdd.push([`cid:${cid}:uid:${post.uid}:pids`, post.timestamp, post.pid]);- if (post.votes > 0) {+ if (post.votes > 0 || post.votes < 0) {bulkAdd.push([`cid:${cid}:uid:${post.uid}:pids:votes`, post.votes, post.pid]);}});diff --git a/src/controllers/accounts/posts.js b/src/controllers/accounts/posts.jsindex d7e2cf000f..9455c1322b 100644--- a/src/controllers/accounts/posts.js+++ b/src/controllers/accounts/posts.js@@ -57,8 +57,7 @@ const templateToData = {return cids.map(c => `cid:${c}:uid:${userData.uid}:pids:votes`);},getTopics: async (sets, req, start, stop) => {- let pids = await db.getSortedSetRevRangeByScore(sets, start, stop, '+inf', '1');- pids = await privileges.posts.filter('topics:read', pids, req.uid);+ const pids = await db.getSortedSetRevRangeByScore(sets, start, stop - start + 1, '+inf', 1);const postObjs = await posts.getPostSummaryByPids(pids, req.uid, { stripTags: false });return { posts: postObjs, nextStart: stop + 1 };},@@ -72,8 +71,7 @@ const templateToData = {return cids.map(c => `cid:${c}:uid:${userData.uid}:pids:votes`);},getTopics: async (sets, req, start, stop) => {- let pids = await db.getSortedSetRangeByScore(sets, start, stop, '-inf', '-1');- pids = await privileges.posts.filter('topics:read', pids, req.uid);+ const pids = await db.getSortedSetRangeByScore(sets, start, stop - start + 1, '-inf', -1);const postObjs = await posts.getPostSummaryByPids(pids, req.uid, { stripTags: false });return { posts: postObjs, nextStart: stop + 1 };},diff --git a/src/posts/user.js b/src/posts/user.jsindex d94e5e7966..c92c197f69 100644--- a/src/posts/user.js+++ b/src/posts/user.js@@ -158,7 +158,7 @@ module.exports = function (Posts) {bulkAdd.push([`uid:${toUid}:posts`, post.timestamp, post.pid]);bulkAdd.push([`cid:${post.cid}:uid:${toUid}:pids`, post.timestamp, post.pid]);- if (post.votes > 0) {+ if (post.votes > 0 || post.votes < 0) {bulkAdd.push([`cid:${post.cid}:uid:${toUid}:pids:votes`, post.votes, post.pid]);}postsByUser[post.uid] = postsByUser[post.uid] || [];diff --git a/src/topics/fork.js b/src/topics/fork.jsindex 59eb95b783..97b5316656 100644--- a/src/topics/fork.js+++ b/src/topics/fork.js@@ -146,7 +146,7 @@ module.exports = function (Topics) {db.sortedSetAdd(`cid:${topicData[1].cid}:pids`, postData.timestamp, postData.pid),db.sortedSetAdd(`cid:${topicData[1].cid}:uid:${postData.uid}:pids`, postData.timestamp, postData.pid),];- if (postData.votes > 0) {+ if (postData.votes > 0 || postData.votes < 0) {tasks.push(db.sortedSetAdd(`cid:${topicData[1].cid}:uid:${postData.uid}:pids:votes`, postData.votes, postData.pid));}diff --git a/src/upgrades/1.19.2/store_downvoted_posts_in_zset.js b/src/upgrades/1.19.2/store_downvoted_posts_in_zset.jsindex f1752f8974..6b402677b7 100644--- a/src/upgrades/1.19.2/store_downvoted_posts_in_zset.js+++ b/src/upgrades/1.19.2/store_downvoted_posts_in_zset.js@@ -10,25 +10,19 @@ module.exports = {const posts = require('../../posts');const { progress } = this;- await batch.processSortedSet('posts:pid', async (ids) => {- const postData = await posts.getPostsFields(ids, ['uid', 'downvotes']);- const cids = await posts.getCidsByPids(ids);+ await batch.processSortedSet('posts:pid', async (pids) => {+ const postData = await posts.getPostsFields(pids, ['pid', 'uid', 'upvotes', 'downvotes']);+ const cids = await posts.getCidsByPids(pids);- const promises = ids.reduce((memo, pid, idx) => {- const { uid, downvotes } = postData[idx];- const cid = cids[idx];-- if (!downvotes) {- progress.incr();- return memo;+ const bulkAdd = [];+ postData.forEach((post, index) => {+ if (post.votes > 0 || post.votes < 0) {+ const cid = cids[index];+ bulkAdd.push([`cid:${cid}:uid:${post.uid}:pids:votes`, post.votes, post.pid]);}-- memo.push(db.sortedSetAdd(`cid:${cid}:uid:${uid}:pids:votes`, -downvotes, pid));- return memo;- }, []);-- await Promise.all(promises);- progress.incr(promises.length);+ });+ await db.sortedSetAddBulk(bulkAdd);+ progress.incr(postData.length);}, {progress,});