From cce7bd55da7c64055dd4036b622a13dc08265e5c Mon Sep 17 00:00:00 2001 From: minie4 Date: Mon, 28 Aug 2023 11:19:46 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=91=20Prevent=20duplicate=20substituti?= =?UTF-8?q?ons?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Prevent duplication if two substitution plan files are the same --- server/parser/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server/parser/index.js b/server/parser/index.js index 0f508db..3a1e448 100644 --- a/server/parser/index.js +++ b/server/parser/index.js @@ -40,7 +40,17 @@ export class Parser { for (const plan of plans) { const foundPlan = dayPlans.find((e) => e.date == plan.date); if (!foundPlan) dayPlans.push(plan); - else foundPlan.changes.push(...plan.changes); + else { + for (const change of plan.changes) { + // Make sure to not insert the exact same substitution twice + const changeExists = foundPlan.changes.find( + (e) => JSON.stringify(e) == JSON.stringify(change), + ); + if (!changeExists) { + foundPlan.changes.push(change); + } + } + } } // Insert substitutions of all substitution plans for (const plan of dayPlans) {