From b06c6329e4dab9e4408d7a02f5f649a86f2f8575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 17 Jan 2022 19:05:07 -0500 Subject: [PATCH] fix: #10175, fix topic linkbacks duplicating on post edit --- src/topics/posts.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/topics/posts.js b/src/topics/posts.js index 2632f10912..52146c7af0 100644 --- a/src/topics/posts.js +++ b/src/topics/posts.js @@ -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);