mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Improved error handling for batch deleted records
no issue
- Similar handling to one introduced in 8418c829de
- 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
8418c829de
commit
5670d99f46
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