(params: {
tableId: string
workspaceId: string
rowIds: string[]
})
| 454 | * and delete-by-filter). |
| 455 | */ |
| 456 | export async function deleteOrderedRowsByIds(params: { |
| 457 | tableId: string |
| 458 | workspaceId: string |
| 459 | rowIds: string[] |
| 460 | }): Promise<{ id: string; position: number }[]> { |
| 461 | const { tableId, workspaceId, rowIds } = params |
| 462 | if (rowIds.length === 0) return [] |
| 463 | return db.transaction(async (trx) => { |
| 464 | await setTableTxTimeouts(trx, { statementMs: 60_000 }) |
| 465 | const deleted: { id: string; position: number }[] = [] |
| 466 | for (let i = 0; i < rowIds.length; i += TABLE_LIMITS.DELETE_BATCH_SIZE) { |
| 467 | const batch = rowIds.slice(i, i + TABLE_LIMITS.DELETE_BATCH_SIZE) |
| 468 | const rows = await trx |
| 469 | .delete(userTableRows) |
| 470 | .where( |
| 471 | and( |
| 472 | eq(userTableRows.tableId, tableId), |
| 473 | eq(userTableRows.workspaceId, workspaceId), |
| 474 | inArray(userTableRows.id, batch) |
| 475 | ) |
| 476 | ) |
| 477 | .returning({ id: userTableRows.id, position: userTableRows.position }) |
| 478 | deleted.push(...rows) |
| 479 | } |
| 480 | // Fractional ordering: deletes leave order_key untouched, so no recompaction. |
| 481 | if (!(await isFeatureEnabled('tables-fractional-ordering')) && deleted.length > 0) { |
| 482 | const minDeletedPos = deleted.reduce( |
| 483 | (min, r) => (r.position < min ? r.position : min), |
| 484 | deleted[0].position |
| 485 | ) |
| 486 | await compactPositions(trx, tableId, minDeletedPos) |
| 487 | } |
| 488 | return deleted |
| 489 | }) |
| 490 | } |
| 491 | |
| 492 | /** |
| 493 | * Selects one page of row ids to delete for the async delete-job worker: base scope plus a |
no test coverage detected