mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Improved error handling for batch deleted records
no issue - Similar handling to one introduced in 31db3c86800b3268da5485417b16e0fcd8e6579a - Having granular tracking for failed to remove id's would make it possible to return more specific errors to the client
This commit is contained in:
parent
e32ce37a89
commit
4feaf49ca7
1 changed files with 24 additions and 7 deletions
|
@ -40,21 +40,38 @@ async function insert(table, data) {
|
|||
return result;
|
||||
}
|
||||
|
||||
async function delChunkSequential(table, chunk, result) {
|
||||
for (const record of chunk) {
|
||||
try {
|
||||
await db.knex(table).where('id', record).del();
|
||||
result.successful += 1;
|
||||
} catch (err) {
|
||||
result.errors.push(err);
|
||||
result.unsuccessfulIds.push(record);
|
||||
result.unsuccessful += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function delChunk(table, chunk, result) {
|
||||
try {
|
||||
await db.knex(table).whereIn('id', chunk).del();
|
||||
result.successful += chunk.length;
|
||||
} catch (err) {
|
||||
await delChunkSequential(table, chunk, result);
|
||||
}
|
||||
}
|
||||
|
||||
async function del(table, ids) {
|
||||
const result = {
|
||||
successful: 0,
|
||||
unsuccessful: 0,
|
||||
unsuccessfulIds: [],
|
||||
errors: []
|
||||
};
|
||||
|
||||
for (const chunk of _.chunk(ids, CHUNK_SIZE)) {
|
||||
try {
|
||||
await db.knex(table).whereIn('id', chunk).del();
|
||||
result.successful += chunk.length;
|
||||
} catch (error) {
|
||||
result.unsuccessful += chunk.length;
|
||||
result.errors.push(error);
|
||||
}
|
||||
await delChunk(table, chunk, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
Loading…
Add table
Reference in a new issue