(
ids: string[],
query: (chunkIds: string[], chunkLimit: number) => Promise<T[]>,
{
overallLimit = DEFAULT_BATCH_SIZE * DEFAULT_MAX_BATCHES_PER_TABLE,
chunkSize = DEFAULT_WORKSPACE_CHUNK_SIZE,
}: SelectByIdChunksOptions = {}
)
| 41 | * timeout. |
| 42 | */ |
| 43 | export async function selectRowsByIdChunks<T>( |
| 44 | ids: string[], |
| 45 | query: (chunkIds: string[], chunkLimit: number) => Promise<T[]>, |
| 46 | { |
| 47 | overallLimit = DEFAULT_BATCH_SIZE * DEFAULT_MAX_BATCHES_PER_TABLE, |
| 48 | chunkSize = DEFAULT_WORKSPACE_CHUNK_SIZE, |
| 49 | }: SelectByIdChunksOptions = {} |
| 50 | ): Promise<T[]> { |
| 51 | if (ids.length === 0) return [] |
| 52 | |
| 53 | const rows: T[] = [] |
| 54 | for (const chunkIds of chunkArray(ids, chunkSize)) { |
| 55 | if (rows.length >= overallLimit) break |
| 56 | const remaining = overallLimit - rows.length |
| 57 | const chunkRows = await query(chunkIds, remaining) |
| 58 | rows.push(...chunkRows) |
| 59 | } |
| 60 | return rows |
| 61 | } |
| 62 | |
| 63 | export interface TableCleanupResult { |
| 64 | table: string |
no test coverage detected