diff --git a/src/ssb.db.c b/src/ssb.db.c index c30ce94c..8b6a6f24 100644 --- a/src/ssb.db.c +++ b/src/ssb.db.c @@ -107,10 +107,25 @@ void tf_ssb_db_init(tf_ssb_t* ssb) ")"); _tf_ssb_db_exec(db, "CREATE INDEX IF NOT EXISTS identities_user ON identities (user, public_key)"); - if (!_tf_ssb_db_has_rows(db, "PRAGMA table_list('messages_fts')") || - sqlite3_exec(db, "INSERT INTO messages_fts(messages_fts, rank) VALUES ('integrity-check', 0)", NULL, NULL, NULL) == SQLITE_CORRUPT_VTAB) + bool populate_fts = false; + if (!_tf_ssb_db_has_rows(db, "PRAGMA table_list('messages_fts')")) { _tf_ssb_db_exec(db, "CREATE VIRTUAL TABLE IF NOT EXISTS messages_fts USING fts5(content, content=messages, content_rowid=rowid)"); + populate_fts = true; + } + + if (!populate_fts) + { + printf("Checking FTS5 integrity...\n"); + if (sqlite3_exec(db, "INSERT INTO messages_fts(messages_fts, rank) VALUES ('integrity-check', 0)", NULL, NULL, NULL) == SQLITE_CORRUPT_VTAB) + { + populate_fts = true; + } + printf("Done.\n"); + } + + if (populate_fts) + { printf("Populating full-text search...\n"); _tf_ssb_db_exec(db, "INSERT INTO messages_fts (rowid, content) SELECT rowid, content FROM messages"); printf("Done.\n");