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

fix(search): tag search freeze and missing results on large DBs (#4243)

Gaurav Singhe1483f189c1a
diff --git a/apps/screenpipe-app-tauri/components/rewind/search-modal.tsx b/apps/screenpipe-app-tauri/components/rewind/search-modal.tsx
index 915d0e7a6..9bea776f3 100644
--- a/apps/screenpipe-app-tauri/components/rewind/search-modal.tsx
+++ b/apps/screenpipe-app-tauri/components/rewind/search-modal.tsx
@@ -889,33 +889,36 @@ export function SearchModal({ isOpen, onClose, onNavigateToTimestamp, embedded =
(async () => {
setIsSearchingTags(true);
try {
- // Fetch all distinct tags with counts from the tags + vision_tags tables
+ // Query the tags table directly (distinct names only), not vision_tags.
+ // count was only used for ORDER BY and is never displayed, so we drop the
+ // GROUP BY aggregate over vision_tags — that full-table scan is what froze
+ // the UI on large DBs. LIKE is ASCII case-insensitive by default, so the
+ // lowercased query matches regardless of tag casing (ASCII only). LIMIT 500
+ // keeps low-count unique tags (e.g. per-session workflow tags with count=1)
+ // so specific long queries still find their target.
+ const safeTagQuery = tagQuery.replace(/'/g, "''");
+ const tagsSQL = tagQuery.length > 0
+ ? `SELECT name FROM tags WHERE name LIKE '%${safeTagQuery}%' COLLATE NOCASE ORDER BY name LIMIT 500`
+ : `SELECT name FROM tags ORDER BY name LIMIT 500`;
+
const tagsResp = await localFetch("/raw_sql", {
method: "POST",
headers: { "Content-Type": "application/json" },
- body: JSON.stringify({
- query: "SELECT t.name, COUNT(vt.vision_id) as count FROM tags t JOIN vision_tags vt ON t.id = vt.tag_id GROUP BY t.id, t.name ORDER BY count DESC",
- }),
+ body: JSON.stringify({ query: tagsSQL }),
signal: AbortSignal.timeout(5000),
});
if (cancelled) return;
- const allDbTags: { name: string; count: number }[] = tagsResp.ok
+ const allDbTags: { name: string }[] = tagsResp.ok
? await tagsResp.json()
: [];
- // Set autocomplete pills (filtered if user typed something after #)
+ // SQL already filtered by tagQuery — use results directly
const tagNames = allDbTags.map(t => t.name);
- setAllTags(
- tagQuery.length > 0
- ? tagNames.filter(t => t.toLowerCase().includes(tagQuery))
- : tagNames
- );
+ setAllTags(tagNames);
- // Find tags that match the query
- const matched = tagQuery.length > 0
- ? allDbTags.filter(t => t.name.toLowerCase().includes(tagQuery))
- : allDbTags;
+ // All returned tags already match the query
+ const matched = allDbTags;
if (matched.length > 0 && !cancelled) {
// Fetch frames tagged with matching tags