From ddf14b0cdd363cb96e9851cff20c425955afb90b Mon Sep 17 00:00:00 2001 From: Eric Mc Sween Date: Fri, 20 Jan 2023 09:10:30 -0500 Subject: [PATCH] Merge pull request #11355 from overleaf/em-delete-project-no-chunks Fix crash when there are no chunks to delete GitOrigin-RevId: 3cdb77da16fe2922888e40e469740579bc4a9b8b --- services/history-v1/storage/lib/chunk_store/postgres.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/history-v1/storage/lib/chunk_store/postgres.js b/services/history-v1/storage/lib/chunk_store/postgres.js index fc154116e2..835ec8c171 100644 --- a/services/history-v1/storage/lib/chunk_store/postgres.js +++ b/services/history-v1/storage/lib/chunk_store/postgres.js @@ -199,7 +199,6 @@ async function deleteChunk(projectId, chunkId) { async function deleteProjectChunks(projectId) { projectId = parseInt(projectId, 10) assert.integer(projectId, 'bad projectId') - assert.integer(projectId, 'bad projectId') knex.transaction(async tx => { await _deleteChunks(knex, { doc_id: projectId }) @@ -208,6 +207,9 @@ async function deleteProjectChunks(projectId) { async function _deleteChunks(tx, whereClause) { const rows = await tx('chunks').returning('*').where(whereClause).del() + if (rows.length === 0) { + return + } const oldChunks = rows.map(row => ({ doc_id: row.doc_id,