MCPcopy Index your code
hub / github.com/simstudioai/sim / reserveBatchPositions

Function reserveBatchPositions

apps/sim/lib/table/rows/ordering.ts:125–140  ·  view source on GitHub ↗
(
  trx: DbTransaction,
  tableId: string,
  count: number,
  requestedPositions?: number[]
)

Source from the content-addressed store, hash-verified

123 * original order; otherwise returns a contiguous append range.
124 */
125export async function reserveBatchPositions(
126 trx: DbTransaction,
127 tableId: string,
128 count: number,
129 requestedPositions?: number[]
130): Promise<number[]> {
131 await acquireRowOrderLock(trx, tableId)
132 if (requestedPositions && requestedPositions.length > 0) {
133 for (const pos of [...requestedPositions].sort((a, b) => a - b)) {
134 await shiftRowsUpFrom(trx, tableId, pos)
135 }
136 return requestedPositions
137 }
138 const start = await nextRowPosition(trx, tableId)
139 return Array.from({ length: count }, (_, i) => start + i)
140}
141
142/**
143 * Recompacts row positions to be contiguous after a bulk delete. With

Callers 1

batchInsertRowsWithTxFunction · 0.90

Calls 3

acquireRowOrderLockFunction · 0.85
shiftRowsUpFromFunction · 0.85
nextRowPositionFunction · 0.85

Tested by

no test coverage detected