From 9a84dc19e99b4b13c3441deda50265adf9c9a137 Mon Sep 17 00:00:00 2001 From: Greg Heartsfield Date: Wed, 4 Jan 2023 16:51:02 -0600 Subject: [PATCH] perf: author/kind index added (schema v13) --- src/schema.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/schema.rs b/src/schema.rs index 5835ebb..88abf1b 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -20,7 +20,7 @@ pragma mmap_size = 17179869184; -- cap mmap at 16GB "##; /// Latest database version -pub const DB_VERSION: usize = 12; +pub const DB_VERSION: usize = 13; /// Schema definition const INIT_SQL: &str = formatcp!( @@ -53,6 +53,7 @@ CREATE INDEX IF NOT EXISTS author_index ON event(author); CREATE INDEX IF NOT EXISTS created_at_index ON event(created_at); CREATE INDEX IF NOT EXISTS delegated_by_index ON event(delegated_by); CREATE INDEX IF NOT EXISTS event_composite_index ON event(kind,created_at); +CREATE INDEX IF NOT EXISTS kind_author_index ON event(kind,author); -- Tag Table -- Tag values are stored as either a BLOB (if they come in as a @@ -175,6 +176,9 @@ pub fn upgrade_db(conn: &mut PooledConnection) -> Result<()> { if curr_version == 11 { curr_version = mig_11_to_12(conn)?; } + if curr_version == 12 { + curr_version = mig_12_to_13(conn)?; + } if curr_version == DB_VERSION { info!( @@ -500,3 +504,23 @@ fn mig_11_to_12(conn: &mut PooledConnection) -> Result { info!("vacuumed DB after hidden event cleanup in {:?}", start.elapsed()); Ok(12) } + +fn mig_12_to_13(conn: &mut PooledConnection) -> Result { + info!("database schema needs update from 12->13"); + let upgrade_sql = r##" +CREATE INDEX IF NOT EXISTS kind_author_index ON event(kind,author); +reindex; +pragma optimize; +PRAGMA user_version = 13; +"##; + match conn.execute_batch(upgrade_sql) { + Ok(()) => { + info!("database schema upgraded v12 -> v13"); + } + Err(err) => { + error!("update failed: {}", err); + panic!("database could not be upgraded"); + } + } + Ok(13) +}