From 20e12d504a2479b530a9b7a1cc0b5ce8be23b372 Mon Sep 17 00:00:00 2001 From: kert Date: Fri, 11 Sep 2026 18:20:58 -0400 Subject: [PATCH] perf(zot): create_db runs the schema script as one transaction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/zot/schema.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/zot/schema.py b/src/zot/schema.py index 4a61465..8e6a409 100644 --- a/src/zot/schema.py +++ b/src/zot/schema.py @@ -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