fix: #10175, fix topic linkbacks duplicating on post edit

isekai-main
Barış Soner Uşaklı 3 years ago
parent 8b06d3770d
commit b06c6329e4

@ -370,13 +370,13 @@ module.exports = function (Topics) {
}
const { pid, uid, tid } = postData;
let add = matches.map(match => match[1]);
let add = matches.map(match => match[1]).map(tid => parseInt(tid, 10));
const now = Date.now();
const topicsExist = await Topics.exists(add);
const current = (await db.getSortedSetMembers(`pid:${pid}:backlinks`)).map(tid => parseInt(tid, 10));
const remove = current.filter(tid => !add.includes(tid));
add = add.filter((_tid, idx) => topicsExist[idx] && !current.includes(_tid) && tid !== parseInt(_tid, 10));
add = add.filter((_tid, idx) => topicsExist[idx] && !current.includes(_tid) && tid !== _tid);
// Remove old backlinks
await db.sortedSetRemove(`pid:${pid}:backlinks`, remove);

Loading…
Cancel
Save