perf: author/kind index added (schema v13)

This commit is contained in:
Greg Heartsfield 2023-01-04 16:51:02 -06:00
parent 20c4bb42eb
commit 9a84dc19e9

View File

@ -20,7 +20,7 @@ pragma mmap_size = 17179869184; -- cap mmap at 16GB
"##; "##;
/// Latest database version /// Latest database version
pub const DB_VERSION: usize = 12; pub const DB_VERSION: usize = 13;
/// Schema definition /// Schema definition
const INIT_SQL: &str = formatcp!( 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 created_at_index ON event(created_at);
CREATE INDEX IF NOT EXISTS delegated_by_index ON event(delegated_by); 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 event_composite_index ON event(kind,created_at);
CREATE INDEX IF NOT EXISTS kind_author_index ON event(kind,author);
-- Tag Table -- Tag Table
-- Tag values are stored as either a BLOB (if they come in as a -- 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 { if curr_version == 11 {
curr_version = mig_11_to_12(conn)?; curr_version = mig_11_to_12(conn)?;
} }
if curr_version == 12 {
curr_version = mig_12_to_13(conn)?;
}
if curr_version == DB_VERSION { if curr_version == DB_VERSION {
info!( info!(
@ -500,3 +504,23 @@ fn mig_11_to_12(conn: &mut PooledConnection) -> Result<usize> {
info!("vacuumed DB after hidden event cleanup in {:?}", start.elapsed()); info!("vacuumed DB after hidden event cleanup in {:?}", start.elapsed());
Ok(12) Ok(12)
} }
fn mig_12_to_13(conn: &mut PooledConnection) -> Result<usize> {
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)
}