Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

perf: partial indexes for the periodic goal-run, rescue and app-doc scans

mattmillartechf58d0f8dc2ea
diff --git a/server/message-db.ts b/server/message-db.ts
index 0055fee47f..0c50f4d0e3 100644
--- a/server/message-db.ts
+++ b/server/message-db.ts
@@ -63,6 +63,10 @@ function open(): DatabaseSync {
CREATE INDEX IF NOT EXISTS messages_work_at ON messages(kind, at) WHERE ${WORK_KINDS};
CREATE INDEX IF NOT EXISTS messages_cards_at ON messages(kind, at) WHERE ${CARD_KINDS};
CREATE INDEX IF NOT EXISTS messages_failed_at ON messages(at) WHERE ${FAILED_CALL};
+ -- For the periodic scans, whose WHERE clauses no index above repeats.
+ CREATE INDEX IF NOT EXISTS messages_goal_run ON messages(at) WHERE kind = 'goal.run';
+ CREATE INDEX IF NOT EXISTS messages_app ON messages(at) WHERE kind = 'app';
+ CREATE INDEX IF NOT EXISTS messages_open_rescue ON messages(at) WHERE kind = 'activity' AND json_extract(json, '$.tool.rescue') IS NOT NULL AND json_extract(json, '$.tool.rescue.settled') IS NULL AND json_extract(json, '$.tool.rescue.over') IS NULL;
CREATE TABLE IF NOT EXISTS thread_state (
thread_id TEXT PRIMARY KEY,
active_leaf_id TEXT