From dc7d44baf0b9eba6ce8494124ab33d6ee35fe8a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B3pez=20Guimaraes?= Date: Sun, 5 Nov 2023 12:08:47 +0000 Subject: [PATCH] Remove redundant transactions We can update the data directly without a transaction. --- src/middleware/nasc.ts | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/middleware/nasc.ts b/src/middleware/nasc.ts index 8dd6bbe..c55135a 100644 --- a/src/middleware/nasc.ts +++ b/src/middleware/nasc.ts @@ -124,14 +124,9 @@ async function NASCMiddleware(request: express.Request, response: express.Respon // * So, the linked PIDs won't have the user's PID // * anymore. if (!linkedPIDs.includes(pid)) { - const session: mongoose.ClientSession = await databaseConnection().startSession(); - await session.startTransaction(); - device.linked_pids.push(pid); - await device.save({ session }); - - await session.commitTransaction(); + await device.save(); } } } @@ -148,9 +143,6 @@ async function NASCMiddleware(request: express.Request, response: express.Respon // * have the same serial number and MAC address. // * Do we want this? If not, are there other solutions? if (!device && pid) { - const session: mongoose.ClientSession = await databaseConnection().startSession(); - await session.startTransaction(); - device = new Device({ model, serial: serialNumber, @@ -160,9 +152,7 @@ async function NASCMiddleware(request: express.Request, response: express.Respon linked_pids: [pid] }); - await device.save({ session }); - - await session.commitTransaction(); + await device.save(); } if (titleID === '0004013000003202') {