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

Function batchDeleteByWorkspaceAndTimestamp

apps/sim/lib/cleanup/batch-delete.ts:199–224  ·  view source on GitHub ↗
({
  tableDef,
  workspaceIdCol,
  timestampCol,
  workspaceIds,
  retentionDate,
  tableName,
  requireTimestampNotNull = false,
  ...rest
}: BatchDeleteOptions)

Source from the content-addressed store, hash-verified

197 * when there's no per-row side effect (e.g. no S3 files to clean up alongside).
198 */
199export async function batchDeleteByWorkspaceAndTimestamp({
200 tableDef,
201 workspaceIdCol,
202 timestampCol,
203 workspaceIds,
204 retentionDate,
205 tableName,
206 requireTimestampNotNull = false,
207 ...rest
208}: BatchDeleteOptions): Promise<TableCleanupResult> {
209 return chunkedBatchDelete({
210 tableDef,
211 workspaceIds,
212 tableName,
213 selectChunk: (chunkIds, limit) => {
214 const predicates = [inArray(workspaceIdCol, chunkIds), lt(timestampCol, retentionDate)]
215 if (requireTimestampNotNull) predicates.push(isNotNull(timestampCol))
216 return db
217 .select({ id: sql<string>`id` })
218 .from(tableDef)
219 .where(and(...predicates))
220 .limit(limit)
221 },
222 ...rest,
223 })
224}
225
226/**
227 * Delete by explicit ID list, chunked so each statement is its own transaction.

Callers 3

runCleanupLogsFunction · 0.90
runCleanupTasksFunction · 0.90
runCleanupSoftDeletesFunction · 0.90

Calls 2

chunkedBatchDeleteFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected