Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

perf: add sync_id indexes to eliminate vision write stalls, bump v2.2.184

Louis Beaumontac85192a845f
diff --git a/crates/screenpipe-db/src/migrations/20260319000000_add_sync_id_indexes.sql b/crates/screenpipe-db/src/migrations/20260319000000_add_sync_id_indexes.sql
new file mode 100644
index 000000000..c5324cd99
--- /dev/null
+++ b/crates/screenpipe-db/src/migrations/20260319000000_add_sync_id_indexes.sql
@@ -0,0 +1,12 @@
+-- Add missing sync_id indexes to prevent full table scans during sync existence checks.
+-- These queries run on every sync cycle and were causing 1-5s full scans on 300K+ row tables,
+-- cascading into WAL checkpoint delays and 140s+ vision write stalls.
+
+CREATE INDEX IF NOT EXISTS idx_frames_sync_id ON frames(sync_id) WHERE sync_id IS NOT NULL;
+CREATE INDEX IF NOT EXISTS idx_ocr_text_sync_id ON ocr_text(sync_id) WHERE sync_id IS NOT NULL;
+CREATE INDEX IF NOT EXISTS idx_audio_transcriptions_sync_id ON audio_transcriptions(sync_id) WHERE sync_id IS NOT NULL;
+
+-- Also add index for elements join query that scans 4M+ rows.
+-- The query filters frames by timestamp then joins elements — this index lets
+-- SQLite start from frame_id (small result set) instead of source+role (millions).
+CREATE INDEX IF NOT EXISTS idx_elements_frame_source_role ON elements(frame_id, source, role) WHERE text IS NOT NULL;
diff --git a/crates/screenpipe-db/src/types.rs b/crates/screenpipe-db/src/types.rs
index a5bb51db1..a1f13cce2 100644
--- a/crates/screenpipe-db/src/types.rs
+++ b/crates/screenpipe-db/src/types.rs
@@ -784,3 +784,21 @@ mod tests {
);
}
}
+
+/// A notification record from the `notifications` table.
+#[derive(Debug, Clone, Serialize, Deserialize, OaSchema, FromRow)]
+pub struct NotificationRecord {
+ pub id: i64,
+ pub pipe_name: String,
+ pub title: String,
+ pub body: Option<String>,
+ pub icon: Option<String>,
+ pub priority: String,
+ pub timeout_secs: Option<i64>,
+ /// JSON-encoded array of action objects.
+ pub actions: Option<String>,
+ pub status: String,
+ pub actioned_id: Option<String>,
+ pub created_at: String,
+ pub actioned_at: Option<String>,
+}