From f794f84e9035d92817259d63de39f178d3c94b04 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 31 Jul 2024 15:00:30 +0200 Subject: [PATCH] Fix quote count --- packages/server/src/api/controllers/table/utils.ts | 6 +++++- packages/server/src/api/routes/tests/row.spec.ts | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/server/src/api/controllers/table/utils.ts b/packages/server/src/api/controllers/table/utils.ts index 51f7b0e589..417cb22fe3 100644 --- a/packages/server/src/api/controllers/table/utils.ts +++ b/packages/server/src/api/controllers/table/utils.ts @@ -183,6 +183,8 @@ export async function handleDataImport( const finalData = await importToRows(data, table, user) + let newRowCount = finalData.length + //Set IDs of finalData to match existing row if an update is expected if (identifierFields.length > 0) { const allDocs = await db.allDocs( @@ -204,12 +206,14 @@ export async function handleDataImport( if (match) { finalItem._id = doc._id finalItem._rev = doc._rev + + newRowCount-- } }) }) } - await quotas.addRows(finalData.length, () => db.bulkDocs(finalData), { + await quotas.addRows(newRowCount, () => db.bulkDocs(finalData), { tableId: table._id, }) diff --git a/packages/server/src/api/routes/tests/row.spec.ts b/packages/server/src/api/routes/tests/row.spec.ts index b448d46e6a..c4586263f4 100644 --- a/packages/server/src/api/routes/tests/row.spec.ts +++ b/packages/server/src/api/routes/tests/row.spec.ts @@ -1320,6 +1320,7 @@ describe.each([ description: "Existing description", }) + const rowUsage = await getRowUsage() await config.api.row.bulkImport(table._id!, { rows: [ @@ -1346,6 +1347,8 @@ describe.each([ expect(rows[1].description).toEqual("Row 2 description") expect(rows[2].name).toEqual("Updated existing row") expect(rows[2].description).toEqual("Existing description") + + await assertRowUsage(rowUsage + 2) }) // Upserting isn't yet supported in MSSQL, see: