fix: controversial posts/bests posts not showing anything

fix upgrade script so posts with negative votes are stored, a post can have 10 upvotes and 2 downvotes
fix missing negative votes checks
remove unnecessary pids flters since the cids are only already filtered by topics:read
isekai-main
Barış Soner Uşaklı 3 years ago
parent e6185883ba
commit 079c487dcb

@ -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]);
}
});

@ -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 };
},

@ -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] || [];

@ -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));
}

@ -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,
});

Loading…
Cancel
Save