mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-06 20:41:17 +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) {
|
async function deleteFromReplies(postData) {
|
||||||
const arrayOfReplyPids = await db.getSortedSetsMembers(postData.map(p => `pid:${p.pid}:replies`));
|
// Any replies to deleted posts will retain toPid reference (gh#13527)
|
||||||
const allReplyPids = _.flatten(arrayOfReplyPids);
|
await db.deleteAll(postData.map(p => `pid:${p.pid}:replies`));
|
||||||
const promises = [
|
|
||||||
db.deleteObjectFields(
|
|
||||||
allReplyPids.map(pid => `post:${pid}`), ['toPid']
|
|
||||||
),
|
|
||||||
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 postsWithParents = postData.filter(p => parseInt(p.toPid, 10));
|
||||||
const bulkRemove = postsWithParents.map(p => [`pid:${p.toPid}:replies`, p.pid]);
|
const bulkRemove = postsWithParents.map(p => [`pid:${p.toPid}:replies`, p.pid]);
|
||||||
promises.push(db.sortedSetRemoveBulk(bulkRemove));
|
await db.sortedSetRemoveBulk(bulkRemove);
|
||||||
await Promise.all(promises);
|
|
||||||
|
|
||||||
|
// Recalculate reply count
|
||||||
const parentPids = _.uniq(postsWithParents.map(p => p.toPid));
|
const parentPids = _.uniq(postsWithParents.map(p => p.toPid));
|
||||||
const counts = await db.sortedSetsCard(parentPids.map(pid => `pid:${pid}:replies`));
|
const counts = await db.sortedSetsCard(parentPids.map(pid => `pid:${pid}:replies`));
|
||||||
await db.setObjectBulk(parentPids.map((pid, index) => [`post:${pid}`, { replies: counts[index] }]));
|
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)))
|
.filter(p => p && p.hasOwnProperty('toPid') && (activitypub.helpers.isUri(p.toPid) || utils.isNumber(p.toPid)))
|
||||||
.map(postObj => postObj.toPid);
|
.map(postObj => postObj.toPid);
|
||||||
|
|
||||||
|
const exists = await posts.exists(parentPids);
|
||||||
|
parentPids = parentPids.filter((_, idx) => exists[idx]);
|
||||||
|
|
||||||
if (!parentPids.length) {
|
if (!parentPids.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user