From 561ce349f9f56e7470867b533ecce34fa607122c Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 28 Jan 2021 14:03:19 +0000 Subject: [PATCH] Fixing an issue that aptkingston found with relationships were links on the way out would be multiplied (due to the bi-directional nature). --- packages/server/src/db/linkedRows/linkUtils.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/server/src/db/linkedRows/linkUtils.js b/packages/server/src/db/linkedRows/linkUtils.js index 3a9aff6c33..5f9dca4088 100644 --- a/packages/server/src/db/linkedRows/linkUtils.js +++ b/packages/server/src/db/linkedRows/linkUtils.js @@ -77,11 +77,21 @@ exports.getLinkDocuments = async function({ } params.include_docs = !!includeDocs try { - const response = await db.query(getQueryIndex(ViewNames.LINK), params) + let linkRows = (await db.query(getQueryIndex(ViewNames.LINK), params)).rows + // filter to get unique entries + const foundIds = [] + linkRows = linkRows.filter(link => { + const unique = foundIds.indexOf(link.id) === -1 + if (unique) { + foundIds.push(link.id) + } + return unique + }) + if (includeDocs) { - return response.rows.map(row => row.doc) + return linkRows.map(row => row.doc) } else { - return response.rows.map(row => row.value) + return linkRows.map(row => row.value) } } catch (err) { // check if the view doesn't exist, it should for all new instances