Skip to content

Commit 030a315

Browse files
authored
Merge pull request #1347 from input-output-hk/greg/1327/enhance_performances
enhance Aggregator SQLite performances
2 parents c974b6a + c77fa80 commit 030a315

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-aggregator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-aggregator"
3-
version = "0.4.9"
3+
version = "0.4.10"
44
description = "A Mithril Aggregator server"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-aggregator/src/commands/serve_command.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl ServeCommand {
164164
}
165165

166166
join_set.spawn(async { tokio::signal::ctrl_c().await.map_err(|e| e.to_string()) });
167-
dependencies_builder.vanish();
167+
dependencies_builder.vanish().await;
168168

169169
if let Err(e) = join_set.join_next().await.unwrap()? {
170170
crit!("A critical error occurred: {e}");

mithril-aggregator/src/dependency_injection/builder.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,13 @@ impl DependenciesBuilder {
258258
}
259259

260260
// configure session
261+
connection
262+
.execute("pragma journal_mode = wal; pragma synchronous = normal;")
263+
.map_err(|e| DependenciesBuilderError::Initialization {
264+
message: "SQLite initialization: could not enable WAL.".to_string(),
265+
error: Some(e.into()),
266+
})?;
267+
261268
connection
262269
.execute("pragma foreign_keys=true")
263270
.map_err(|e| DependenciesBuilderError::Initialization {
@@ -273,6 +280,12 @@ impl DependenciesBuilder {
273280
Ok(connection)
274281
}
275282

283+
async fn drop_sqlite_connection(&self) {
284+
if let Some(connection) = &self.sqlite_connection {
285+
let _ = connection.execute("pragma analysis_limit=400; pragma optimize;");
286+
}
287+
}
288+
276289
/// Get SQLite connection
277290
pub async fn get_sqlite_connection(&mut self) -> Result<Arc<ConnectionWithFullMutex>> {
278291
if self.sqlite_connection.is_none() {
@@ -1196,5 +1209,7 @@ impl DependenciesBuilder {
11961209
}
11971210

11981211
/// Remove the dependencies builder from memory to release Arc.
1199-
pub fn vanish(self) {}
1212+
pub async fn vanish(self) {
1213+
self.drop_sqlite_connection().await;
1214+
}
12001215
}

0 commit comments

Comments
 (0)