fix: dont add duplicate link backs

This commit is contained in:
Barış Soner Uşaklı
2022-01-18 20:12:50 -05:00
parent 78cd6de7e7
commit 3b72ff8742

View File

@@ -370,7 +370,7 @@ module.exports = function (Topics) {
}
const { pid, uid, tid } = postData;
let add = matches.map(match => match[1]).map(tid => parseInt(tid, 10));
let add = _.uniq(matches.map(match => match[1]).map(tid => parseInt(tid, 10)));
const now = Date.now();
const topicsExist = await Topics.exists(add);
@@ -382,7 +382,7 @@ module.exports = function (Topics) {
await db.sortedSetRemove(`pid:${pid}:backlinks`, remove);
// Add new backlinks
await db.sortedSetAdd(`pid:${pid}:backlinks`, add.map(Number.bind(null, now)), add);
await db.sortedSetAdd(`pid:${pid}:backlinks`, add.map(() => now), add);
await Promise.all(add.map(async (tid) => {
await Topics.events.log(tid, {
uid,