Skip to content

[P0/arch] Query history belongs in SQLite, not localStorage #585

Closed

Description

@EVWorth

Context

src/stores/historyStore.ts persists the whole entry array to localStorage under mas-query-history via zustand/middleware::persist.

Problem

localStorage is the wrong medium for an append-only log that grows with use:

  • Shared quota. 5–10 MB per origin, shared with sqlpilot-query-settings, sqlpilot-formatter-settings and mas-query-favorites. A large history can push the others out.
  • Silent loss. persist swallows a quota failure. History stops recording and nothing says so.
  • Whole-array rewrite on every query. Serialising and writing the full array synchronously on each addEntry is [P1/arch] Every addEntry writes the entire entries array to localStorage synchronously — no debounce #331, which only exists because of this medium.
  • Wiped with site data. Not a durable record.
  • Unbounded entries. One pasted migration script is stored whole and can consume the quota by itself.

Every comparable client (DBeaver, DataGrip, MySQL Workbench) keeps history in a file or embedded database.

Precedent in this repo

ConnectionStore (src-tauri/crates/mas-core/src/connection/store.rs) is already SQLite with a migrations module. ARCHITECTURE §9.4 notes a query_history table from earlier drafts that was never implemented.

Expected

History in a local SQLite database. Writes are async and do not block the UI thread. Entry SQL is capped at a sane size with a marker when truncated. A migration imports whatever is in localStorage on first run, then clears the key.

Notes

Supersedes #331 — debouncing is a workaround for the medium, not a fix.

Acceptance

History survives clearing browser site data; adding an entry does not serialise the full history; a 10 MB statement does not consume the store; existing localStorage history is imported once.

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/historykind/archseverity/p0

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions