From 6c82c1e785847986d9adda4fc4c3d637f94d37fe Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Sat, 11 Jul 2020 14:23:51 -0400 Subject: Replace time index with (context, time) index This is what it should have been... --- database.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/database.h b/database.h index e2d52ff..46679f5 100644 --- a/database.h +++ b/database.h @@ -42,7 +42,7 @@ #define DATABASE_PATH "litterbox/litterbox.sqlite" -enum { DatabaseVersion = 4 }; +enum { DatabaseVersion = 5 }; #define ENUM_TYPE \ X(Privmsg, "privmsg") \ @@ -282,7 +282,7 @@ static const char *InitSQL = SQL( target TEXT, message TEXT ); - CREATE INDEX eventsTime ON events (time); + CREATE INDEX eventsContextTime ON events (context, time); CREATE VIEW text ( event, network, channel, query, nick, user, target, message @@ -323,7 +323,7 @@ static const char *InitSQL = SQL( UNIQUE (host, port) ); - PRAGMA user_version = 4; + PRAGMA user_version = 5; COMMIT TRANSACTION; ); @@ -370,9 +370,17 @@ static const char *MigrationSQL[] = { UPDATE motds SET time = strftime('%s', time); UPDATE topics SET time = strftime('%s', time); UPDATE events SET time = strftime('%s', time); - CREATE INDEX IF NOT EXISTS eventsTime ON events (time); + // Don't bother creating the index that will be immediately dropped in + // version 5. + // CREATE INDEX IF NOT EXISTS eventsTime ON events (time); PRAGMA user_version = 4; ), + + SQL( + DROP INDEX IF EXISTS eventsTime; + CREATE INDEX eventsContextTime ON events (context, time); + PRAGMA user_version = 5; + ), }; static inline void dbMigrate(void) { -- cgit 1.4.1