[projects/pld-builder.new] db: read the last good builds from an index alone
arekm
arekm at pld-linux.org
Sat Nov 21 11:37:35 CET 2026
commit e1d07911c21de2e42a07c0e6b48d23492c1462e7
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Sat Nov 21 11:32:32 2026 +0100
db: read the last good builds from an index alone
The query read every matching row from the table, one disk read each:
on a busy disk queue.html took minutes, under the queue lock.
PLD_Builder/db.py | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
---
diff --git a/PLD_Builder/db.py b/PLD_Builder/db.py
index 59ca518..1e96aac 100644
--- a/PLD_Builder/db.py
+++ b/PLD_Builder/db.py
@@ -24,12 +24,13 @@ CREATE TABLE IF NOT EXISTS builds (
ended REAL NOT NULL,
PRIMARY KEY (batch_id, builder)
);
-CREATE INDEX IF NOT EXISTS builds_by_spec ON builds (spec, builder, ended);
+-- everything ok_builds() reads, so it reads no row of the table itself
+CREATE INDEX IF NOT EXISTS builds_ok ON builds (spec, status, builder, ended, started, batch_id);
"""
# the version of SCHEMA, kept in the file: a later one migrates from the version it finds
-VERSION = 1
+VERSION = 2
@contextlib.contextmanager
@@ -37,7 +38,8 @@ def connect():
"""The database, created on first use; changes are committed when the block ends without an error"""
with contextlib.closing(sqlite3.connect(path.builder_db_file, timeout=60)) as db:
if db.execute("PRAGMA user_version").fetchone()[0] < VERSION:
- db.executescript(SCHEMA + f"PRAGMA user_version = {VERSION};")
+ # builds_by_spec of version 1 was replaced by builds_ok
+ db.executescript(SCHEMA + f"DROP INDEX IF EXISTS builds_by_spec;\nPRAGMA user_version = {VERSION};")
with db:
yield db
@@ -63,7 +65,10 @@ def ok_builds(specs):
with connect() as db:
for spec, builder, batch_id, started, ended in db.execute(
"SELECT spec, builder, batch_id, started, ended FROM builds"
- f" WHERE status LIKE 'OK%' AND spec IN ({', '.join('?' * len(specs))}) ORDER BY ended DESC",
+ # OK and OK_... as a range the index can seek
+ f" WHERE spec IN ({', '.join('?' * len(specs))}) AND status >= 'OK' AND status < 'OL'",
list(specs)):
found.setdefault((spec, builder), []).append((batch_id, started, ended))
+ for builds in found.values():
+ builds.sort(key=lambda b: b[2], reverse=True)
return found
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/projects/pld-builder.new.git/commitdiff/e1d07911c21de2e42a07c0e6b48d23492c1462e7
More information about the pld-cvs-commit
mailing list