Home / Function/ queueRowDeletesWithOptimisticUpdate() — supabase Function Reference

queueRowDeletesWithOptimisticUpdate() — supabase Function Reference

Architecture documentation for the queueRowDeletesWithOptimisticUpdate() function in queueOperationUtils.ts from the supabase codebase.

Entity Profile

Dependency Diagram

graph TD
  a988b2a0_5cc9_1ce7_ff1f_e6e71ffd3e3c["queueRowDeletesWithOptimisticUpdate()"]
  551e2d1d_e518_5db4_b577_49cd04255fb1["removeRow()"]
  a988b2a0_5cc9_1ce7_ff1f_e6e71ffd3e3c -->|calls| 551e2d1d_e518_5db4_b577_49cd04255fb1
  c3ed25f2_a5bf_3779_0009_261419f29eb9["markRowAsDeleted()"]
  a988b2a0_5cc9_1ce7_ff1f_e6e71ffd3e3c -->|calls| c3ed25f2_a5bf_3779_0009_261419f29eb9
  style a988b2a0_5cc9_1ce7_ff1f_e6e71ffd3e3c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/studio/components/grid/utils/queueOperationUtils.ts lines 289–348

export function queueRowDeletesWithOptimisticUpdate({
  rows,
  table,
  queryClient,
  queueOperation,
  projectRef,
}: QueueRowDeletesParams): void {
  // [Ali] We can handle these better in the future
  // right now this is a pretty abnormal case of this occurring
  if (!projectRef) {
    console.error('Cannot queue row deletes: projectRef is required')
    return
  }

  if (!isTableLike(table)) {
    console.error('Cannot queue row deletes: table must be a TableLike entity')
    return
  }

  if (table.primary_keys.length === 0) {
    console.error('Cannot queue row deletes: table has no primary keys')
    return
  }

  for (const row of rows) {
    const rowIdentifiers: Record<string, unknown> = {}
    table.primary_keys.forEach((pk) => {
      rowIdentifiers[pk.name] = row[pk.name]
    })

    queueOperation({
      type: QueuedOperationType.DELETE_ROW,
      tableId: table.id,
      payload: {
        rowIdentifiers,
        originalRow: row,
        table,
      },
    })

    const queryKey = tableRowKeys.tableRows(projectRef, { table: { id: table.id } })
    queryClient.setQueriesData<TableRowsData>({ queryKey }, (old) => {
      if (!old) return old

      // For pending add rows, remove completely
      if (isPendingAddRow(row)) {
        return {
          ...old,
          rows: removeRow(old.rows, rowIdentifiers),
        }
      }

      // For existing rows, mark as deleted
      return {
        ...old,
        rows: markRowAsDeleted(old.rows, rowIdentifiers),
      }
    })
  }
}

Subdomains

Frequently Asked Questions

What does queueRowDeletesWithOptimisticUpdate() do?
queueRowDeletesWithOptimisticUpdate() is a function in the supabase codebase.
What does queueRowDeletesWithOptimisticUpdate() call?
queueRowDeletesWithOptimisticUpdate() calls 2 function(s): markRowAsDeleted, removeRow.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free