Skip to content

[P1][arch] useQueryExecution is a one-consumer abstraction — 12 features bypass it and call api.executeQuery directly #448

Closed

Description

@EVWorth

Context

src/hooks/useQueryExecution.ts was extracted (commit d909ede 2026-04-07) to centralize query-execution context (connection-id, database, isExecuting flag). The doc comment at line 1-9 says: "Centralizes query execution context so callers never have to thread connectionId/database manually." It is used by exactly one component.

Problem

grep -n "useQueryExecution" src/ finds 8 hits: 1 production consumer (QueryToolbar.tsx) + 7 test files. Every other feature that runs SQL bypasses the hook and calls api.executeQuery(connectionId, sql, database) directly:

  • src/components/routine/RoutineViewer.tsx:175
  • src/components/grid/ResultsGrid.tsx (via resultStore)
  • src/components/designer/TableDesigner.tsx
  • src/components/compare/SyncPreview.tsx
  • src/components/backup/RestoreDialog.tsx
  • src/components/import/ImportDialog.tsx
  • src/components/admin/{AdminPanel,UserManagement,CreateUserDialog,ChangePasswordDialog}.tsx
  • src/lib/backup-generator.ts:152

The abstraction exists, but only one consumer uses it. Either delete the hook (paper-tiger) or refactor all 12 bypassers through it (consistency).

The cross-cutting audit (docs/audits/cross-cutting.md F2) flagged this as P1.

Files

  • src/hooks/useQueryExecution.ts:1-64
  • src/components/editor/QueryToolbar.tsx:18, 58 — only consumer
  • 11 other consumer files (listed above)

Repro

grep -rn "useQueryExecution" src/ | grep -v test
# Only QueryToolbar.tsx matches in production code
grep -rn "api\.executeQuery(" src/ | grep -v test
# 13 production call sites

Expected

Either every consumer routes through useQueryExecution().executeQuery(sql) (consistency), or the hook is removed and inlined into QueryToolbar (no dead abstraction). Pick one.

Proposed fix

Scope M. Refactor all 12 bypassers to use the hook. Each consumer calls useQueryExecution().executeQuery(sql) and the hook derives connection-id/database from store state. Or: delete useQueryExecution.ts entirely and inline the connectionId/database derivation in QueryToolbar.

Acceptance

A grep -n "api\.executeQuery(" src/ returns 0 hits outside src/stores/resultStore.ts (which has legitimate reason — it's the result-store, not a feature component). Every consumer either calls useQueryExecution().executeQuery(...) or has a comment justifying the direct call.

Needs human verify

No (refactor only).

Labels: audit, area/cross-cutting, severity/p1, kind/arch

Activity

  1. added
    audit
    severity/p1
    kind/arch
    on Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/cross-cuttingauditkind/archseverity/p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions