From 41c84a92cdf81d9511346ef6ced6ca42401a8a5f Mon Sep 17 00:00:00 2001 From: Saumya Pandey Date: Mon, 15 Mar 2021 17:25:32 +0530 Subject: [PATCH] Remove unnecessary logic from removeIndexCollisions --- server/utils/removeIndexCollisions.js | 32 +++++++++------------------ 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/server/utils/removeIndexCollisions.js b/server/utils/removeIndexCollisions.js index 907ac4f17d..9d2e17817c 100644 --- a/server/utils/removeIndexCollisions.js +++ b/server/utils/removeIndexCollisions.js @@ -6,25 +6,17 @@ import { sequelize } from "../sequelize"; /** * * @param teamId The team id whose collections has to be fetched - * @param index All collections with given index value are given new index value - * @param collections If collections is passed, this is used to form collections array and no db query is made - * @returns An array of collided collections or undefined.If array, rach array element is an array of collection id and its new index [id,newIndex] + * @returns An array or undefined. If array, each array element is an array of collided collection id and its new index [id,newIndex] */ -export default async function removeIndexCollisions( - teamId: string, - index?: string, - collections?: Collection[] -) { - if (!collections) { - collections = await Collection.findAll({ - where: { teamId, deletedAt: null }, - attributes: ["id", "index", "updatedAt"], - order: [ - sequelize.literal('"collection"."index" collate "C"'), - ["updatedAt", "DESC"], - ], - }); - } +export default async function removeIndexCollisions(teamId: string) { + let collections = await Collection.findAll({ + where: { teamId, deletedAt: null }, + attributes: ["id", "index", "updatedAt"], + order: [ + sequelize.literal('"collection"."index" collate "C"'), + ["updatedAt", "DESC"], + ], + }); collections = collections.map((collection) => { return [collection, collection.index]; @@ -33,10 +25,6 @@ export default async function removeIndexCollisions( // a set to store the index value of collections. const indexSet = new Set(); - if (index) { - indexSet.add(index); - } - let collision = false; // make the index null, if there is index collision