Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions src/_canary/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def __init__(self, db_path: Path):
self.path = Path(db_path)
self.path.parent.mkdir(parents=True, exist_ok=True)
self.connection = sqlite3.connect(self.path, timeout=30.0, isolation_level=None)
self.connection.execute("PRAGMA journal_mode=WAL;")
self.connection.execute("PRAGMA synchronous=NORMAL;")
self.connection.execute("PRAGMA journal_mode=MEMORY;")
self.connection.execute("PRAGMA synchronous=OFF;")
self.connection.execute("PRAGMA foreign_key=ON;")

@classmethod
Expand Down Expand Up @@ -178,6 +178,7 @@ def put_specs(self, gen_signature: str, specs: list[ResolvedSpec]) -> None:
meta_rows.append((spec.id, source.as_posix(), view.as_posix(), gen_signature))
for dep in spec.dependencies:
dep_rows.append((spec.id, dep.id))

with self.connection:
self.connection.execute("CREATE TEMP TABLE _spec_ids(id TEXT PRIMARY KEY)")
self.connection.executemany(
Expand All @@ -187,22 +188,37 @@ def put_specs(self, gen_signature: str, specs: list[ResolvedSpec]) -> None:
# 2. Bulk insert/update specs
self.connection.executemany(
"""
INSERT INTO specs (spec_id, data)
VALUES (?, ?)
ON CONFLICT(spec_id) DO UPDATE SET data=excluded.data
""",
INSERT INTO specs (spec_id, data)
VALUES (?, ?)
ON CONFLICT(spec_id) DO UPDATE SET data=excluded.data
""",
spec_rows,
)

self.connection.execute(
"""CREATE TEMP TABLE _meta_tmp(
spec_id TEXT, source TEXT, view TEXT, gen_signature TEXT
)
"""
)

self.connection.executemany(
"""
INSERT INTO specs_meta (spec_id, source, view, gen_signature)
VALUES (?, ?, ?, ?)
ON CONFLICT(spec_id, gen_signature)
DO UPDATE SET source=excluded.source, view=excluded.view
""",
INSERT INTO _meta_tmp(spec_id, source, view, gen_signature)
VALUES (?, ?, ?, ?)
""",
meta_rows,
)

self.connection.execute(
"""
INSERT OR REPLACE INTO specs_meta(spec_id, source, view, gen_signature)
SELECT spec_id, source, view, gen_signature
FROM _meta_tmp
"""
)
self.connection.execute("DROP TABLE _meta_tmp")

# 3. Bulk delete old dependencies for these specs
self.connection.execute(
"DELETE FROM spec_deps WHERE spec_id IN (SELECT id FROM _spec_ids)"
Expand Down Expand Up @@ -300,8 +316,8 @@ def load_specs_by_tagname(self, tag: str) -> list["ResolvedSpec"]:
"""
SELECT s.spec_id, s.data
FROM specs s
JOIN specs_meta sm ON s.spec_id = sm.spec_id
JOIN selections sel ON sel.signature = sm.gen_signature
JOIN selection_specs ss ON ss.spec_id = s.spec_id
JOIN selections sel ON sel.id = ss.selection_id
WHERE sel.tag = ?
""",
(tag,),
Expand Down
2 changes: 1 addition & 1 deletion src/_canary/plugins/subcommands/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def print_tag_info(self, tag: str) -> None:
fh.write(f" --owner {o}\n")
if selection.regex:
fh.write(f"Regular expression filter:\n --regex {selection.regex}\n")
fh.write("Test specs:")
fh.write(f"Test specs ({len(specs)}):")
table = rich.table.Table("No.", "ID", "Name")
for i, spec in enumerate(specs):
table.add_row(str(i), spec.id[:7], spec.display_name(resolve=True, style="rich"))
Expand Down
4 changes: 2 additions & 2 deletions src/_canary/plugins/subcommands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def __call__(
errors.append(f"Cannot mix {request.get('kind')} with scanpaths {item}")
continue
request["kind"] = "scanpaths"
payload: dict[str, list[str]] = request.setdefault("payload", {})
payload = request.setdefault("payload", {})
payload[item] = []
continue

Expand All @@ -331,7 +331,7 @@ def __call__(
continue
request["kind"] = "scanpaths"
root, name = item.split(os.pathsep, 1)
payload: dict[str, list[str]] = request.setdefault("payload", {})
payload = request.setdefault("payload", {})
payload.setdefault(os.path.abspath(root), []).append(
name.replace(os.pathsep, os.path.sep)
)
Expand Down
Loading