mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-11 01:52:55 +01:00
fix: update logic so that purging a post does not remove toPid fields from children, updated addParentPosts so that post existence is checked
This commit is contained in:
@@ -197,20 +197,15 @@ module.exports = function (Posts) {
|
||||
}
|
||||
|
||||
async function deleteFromReplies(postData) {
|
||||
const arrayOfReplyPids = await db.getSortedSetsMembers(postData.map(p => `pid:${p.pid}:replies`));
|
||||
const allReplyPids = _.flatten(arrayOfReplyPids);
|
||||
const promises = [
|
||||
db.deleteObjectFields(
|
||||
allReplyPids.map(pid => `post:${pid}`), ['toPid']
|
||||
),
|
||||
db.deleteAll(postData.map(p => `pid:${p.pid}:replies`)),
|
||||
];
|
||||
// Any replies to deleted posts will retain toPid reference (gh#13527)
|
||||
await db.deleteAll(postData.map(p => `pid:${p.pid}:replies`));
|
||||
|
||||
// Remove post(s) from parents' replies zsets
|
||||
const postsWithParents = postData.filter(p => parseInt(p.toPid, 10));
|
||||
const bulkRemove = postsWithParents.map(p => [`pid:${p.toPid}:replies`, p.pid]);
|
||||
promises.push(db.sortedSetRemoveBulk(bulkRemove));
|
||||
await Promise.all(promises);
|
||||
await db.sortedSetRemoveBulk(bulkRemove);
|
||||
|
||||
// Recalculate reply count
|
||||
const parentPids = _.uniq(postsWithParents.map(p => p.toPid));
|
||||
const counts = await db.sortedSetsCard(parentPids.map(pid => `pid:${pid}:replies`));
|
||||
await db.setObjectBulk(parentPids.map((pid, index) => [`post:${pid}`, { replies: counts[index] }]));
|
||||
|
||||
@@ -184,6 +184,9 @@ module.exports = function (Topics) {
|
||||
.filter(p => p && p.hasOwnProperty('toPid') && (activitypub.helpers.isUri(p.toPid) || utils.isNumber(p.toPid)))
|
||||
.map(postObj => postObj.toPid);
|
||||
|
||||
const exists = await posts.exists(parentPids);
|
||||
parentPids = parentPids.filter((_, idx) => exists[idx]);
|
||||
|
||||
if (!parentPids.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user