search for standard sites pub-search.waow.tech
search zig blog atproto
11
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: keep local not-ready during sync, search uses turso directly

search was blocking on local db mutex during sync batch writes.
now local stays not-ready for the entire sync duration — search
goes straight to turso (which has no mutex). when sync finishes,
local becomes ready and search uses the fast local path.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

zzstoatzz ad4b87f1 f0b5c93a

+6 -5
+6 -5
backend/src/db/sync.zig
··· 10 10 const BATCH_SIZE = 500; 11 11 12 12 /// Full sync: fetch all data from Turso and populate local SQLite 13 - /// Uses brief locks per batch so search queries aren't blocked during sync. 13 + /// Local stays not-ready during sync — search goes to Turso (no mutex there). 14 + /// When sync completes, local becomes ready and search uses the fast local path. 14 15 pub fn fullSync(turso: *Client, local: *LocalDb) !void { 15 16 std.debug.print("sync: starting full sync...\n", .{}); 17 + 18 + local.setReady(false); 16 19 17 20 const conn = local.getConn() orelse return error.LocalNotOpen; 18 21 19 - // clear existing data (brief lock) 22 + // clear existing data 20 23 { 21 24 local.lock(); 22 25 defer local.unlock(); ··· 26 29 conn.exec("DELETE FROM publications", .{}) catch {}; 27 30 conn.exec("DELETE FROM document_tags", .{}) catch {}; 28 31 } 29 - 30 - // mark ready so search can fall through to Turso while we sync 31 - local.setReady(true); 32 32 33 33 // sync documents in batches — fetch from Turso unlocked, write to local with brief lock 34 34 var doc_count: usize = 0; ··· 195 195 }; 196 196 } 197 197 198 + local.setReady(true); 198 199 std.debug.print("sync: full sync complete - {d} docs, {d} pubs, {d} tags, {d} popular, {d} cached\n", .{ doc_count, pub_count, tag_count, popular_count, cache_count }); 199 200 } 200 201