perf(zot): create_db runs the schema script as one transaction
All checks were successful
Deploy / zotero (push) Has been skipped
CI / test (push) Successful in 2m25s
Deploy / docs (push) Has been skipped
Deploy / api (push) Has been skipped
Deploy / llm (push) Has been skipped
Deploy / mc (push) Has been skipped
Infra CI / zotero (push) Successful in 16s
Infra CI / notebooks (push) Successful in 1m11s
CI / lint (push) Successful in 30s
CI / notebooks-smoke (push) Successful in 1m46s
Deploy / notebooks (push) Has been skipped
Infra CI / docs (push) Successful in 1m46s
Infra CI / api (push) Successful in 1m12s
Infra CI / mc (push) Successful in 13s
Deploy / report (push) Successful in 13s
Infra CI / llm (push) Successful in 55s

executescript autocommitted each of the ~2,500 statements — thousands of
fsyncs — so on a file-backed path under disk load a fresh zotero.sqlite
took 15–20 s. Every prisma test that builds one in tmp_path paid it and
the suite looked hung (my own full run sat 42 min; the #655 agent's runs
never returned). One transaction: 0.02 s, integrity_check ok.
This commit is contained in:
kert
2026-09-11 18:20:58 -04:00
parent e1494479aa
commit 20e12d504a

View File

@@ -32,6 +32,11 @@ def create_db(path: str = ":memory:") -> sqlite3.Connection:
close it afterward; for ``:memory:`` keep it alive.
"""
con = sqlite3.connect(path)
con.executescript(_load_sql())
# One transaction for the whole ~2,500-statement script. executescript
# otherwise autocommits every CREATE/INSERT — thousands of fsyncs — and
# on a file-backed path under disk load that took 15–20 s per fresh
# DB (every prisma test that builds a zotero.sqlite in tmp_path paid
# it; the suite looked hung). As one transaction it is ~instant.
con.executescript("BEGIN;\n" + _load_sql() + "\nCOMMIT;")
con.row_factory = sqlite3.Row
return con