Skip to content

Commit 2a1442f

Browse files
committed
perf(antigravity): open each conversation database once
`collect_records` reads two tables, and each read was opening its own read-only connection. Opening once and sharing it halves the connections per conversation, which matters because Antigravity writes one database per conversation rather than one for the whole history.
1 parent 69df140 commit 2a1442f

1 file changed

Lines changed: 22 additions & 16 deletions

File tree

‎rust/adapters/antigravity/src/loader.rs‎

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,13 @@ fn records_to_entries(
8686
entries
8787
}
8888

89-
/// Read every blob column of one conversation database.
90-
fn read_blobs(db_path: &Path, query: &str, shared: &SharedArgs) -> Vec<Vec<u8>> {
91-
let Ok(connection) =
92-
sqlite::Connection::open_with_flags(db_path, sqlite::OpenFlags::new().with_read_only())
93-
else {
94-
debug_log(
95-
shared,
96-
format!(
97-
"Failed to open Antigravity conversation {}",
98-
db_path.display()
99-
),
100-
);
101-
return Vec::new();
102-
};
89+
/// Read every blob column returned by one query.
90+
fn read_blobs(
91+
connection: &sqlite::Connection,
92+
db_path: &Path,
93+
query: &str,
94+
shared: &SharedArgs,
95+
) -> Vec<Vec<u8>> {
10396
// A conversation database created by a different Antigravity version can be
10497
// missing a table entirely, which is a prepare-time error rather than a reason
10598
// to discard the rest of the conversation.
@@ -150,8 +143,21 @@ fn collect_records(db_path: &Path, shared: &SharedArgs) -> Vec<UsageRecord> {
150143
|stem| Arc::from(stem.to_string_lossy().as_ref()),
151144
);
152145

146+
let Ok(connection) =
147+
sqlite::Connection::open_with_flags(db_path, sqlite::OpenFlags::new().with_read_only())
148+
else {
149+
debug_log(
150+
shared,
151+
format!(
152+
"Failed to open Antigravity conversation {}",
153+
db_path.display()
154+
),
155+
);
156+
return Vec::new();
157+
};
158+
153159
// Names first, so both sources can be attributed in one pass.
154-
let generations = read_blobs(db_path, ANTIGRAVITY_GENERATION_QUERY, shared)
160+
let generations = read_blobs(&connection, db_path, ANTIGRAVITY_GENERATION_QUERY, shared)
155161
.iter()
156162
.flat_map(|blob| parse_generation_metadata(blob))
157163
.collect::<Vec<_>>();
@@ -175,7 +181,7 @@ fn collect_records(db_path: &Path, shared: &SharedArgs) -> Vec<UsageRecord> {
175181
};
176182

177183
let mut records = Vec::new();
178-
for blob in read_blobs(db_path, ANTIGRAVITY_STEP_QUERY, shared) {
184+
for blob in read_blobs(&connection, db_path, ANTIGRAVITY_STEP_QUERY, shared) {
179185
let step = parse_step_metadata(&blob);
180186
let Some(timestamp) = step.timestamp else {
181187
// A usage row with no timestamp cannot be placed in any reporting

0 commit comments

Comments
 (0)