From 894ea47462b65bbdff887bc17641dc8bcc71b455 Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Tue, 8 Aug 2023 16:11:16 -0600 Subject: [PATCH] Revert "server/sqlite: don't use content-less fts table" This reverts commit 427bd50b8dd456fdcf07cd32a0dd2b3ca0009203. --- src/commands/sqlite/fts.rs | 5 +++-- src/sqlite/connection.rs | 10 ---------- src/sqlite/importer.rs | 8 ++++++-- src/sqlite/util.rs | 9 +++++++-- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/commands/sqlite/fts.rs b/src/commands/sqlite/fts.rs index 749a4f2c..6e155832 100644 --- a/src/commands/sqlite/fts.rs +++ b/src/commands/sqlite/fts.rs @@ -89,6 +89,7 @@ fn reindex_fts(tx: &Transaction) -> Result { let mut count = 0; while let Some(row) = rows.next()? { let rowid: u64 = row.get(0)?; + let timestamp: u64 = row.get(1)?; let source: String = row.get(2)?; let source: Value = serde_json::from_str(&source)?; let flat = extract_values(&source); @@ -98,8 +99,8 @@ fn reindex_fts(tx: &Transaction) -> Result { params![&flat, rowid], )?; tx.execute( - "insert into fts (rowid, source_values) values (?, ?)", - params![rowid, &flat], + "insert into fts (rowid, timestamp, source_values) values (?, ?, ?)", + params![rowid, timestamp, &flat], )?; count += 1; diff --git a/src/sqlite/connection.rs b/src/sqlite/connection.rs index 53f0b85d..a1f542f8 100644 --- a/src/sqlite/connection.rs +++ b/src/sqlite/connection.rs @@ -142,8 +142,6 @@ pub fn init_event_db(db: &mut Connection) -> Result<(), rusqlite::Error> { tx.commit()?; } else if !db.has_table("fts")? { info!("FTS not enabled, consider enabling for query performance improvements"); - } else { - check_0_17_broken_fts(db); } Ok(()) @@ -176,14 +174,6 @@ pub(crate) fn get_pragma(db: &Connection, name: &str) -> Result Result<(), rusqlite::Error> { - tx.execute("create virtual table fts using fts5(source_values)", [])?; + tx.execute( + "create virtual table fts + using fts5(timestamp unindexed, source_values, content=events, content_rowid=rowid)", + [], + )?; tx.execute( " create trigger events_ad_trigger after delete on events begin - delete from fts where rowid = old.rowid; + insert into fts(fts, rowid, timestamp, source_values) + values ('delete', old.rowid, old.timestamp, old.source_values); end", [], )?;