From b9aff50de98eb9789b6e592a9e8e01adf287fd16 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Mon, 27 May 2024 19:47:58 -0400 Subject: [PATCH] perf: don't read full line_bits table each time --- coverage/sqldata.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/coverage/sqldata.py b/coverage/sqldata.py index 5dd29f67c..c6ba11a94 100644 --- a/coverage/sqldata.py +++ b/coverage/sqldata.py @@ -789,16 +789,14 @@ def update( if lines: self._choose_lines_or_arcs(lines=True) - with con.execute( - "select file.path, context.context, line_bits.numbits " + - "from line_bits " + - "inner join file on file.id = line_bits.file_id " + - "inner join context on context.id = line_bits.context_id", - ) as cur: - for path, context, numbits in cur: - key = (aliases_map(path), context) - if key in lines: - lines[key] = numbits_union(lines[key], numbits) + for (file, context), numbits in lines.items(): + with con.execute( + "select numbits from line_bits where file_id = ? and context_id = ?", + (file_ids[file], context_ids[context]), + ) as cur: + existing = list(cur) + if existing: + lines[(file, context)] = numbits_union(numbits, existing[0][0]) con.executemany_void( "insert or replace into line_bits " +