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.

perf: add turso keepalive ping every 3 minutes

prevents ~1s TLS handshake on first query after idle.
same pattern as existing tpuf keepalive.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

+29
+4
backend/src/db.zig
··· 60 60 return null; 61 61 } 62 62 63 + pub fn startKeepalive() void { 64 + if (client) |*c| c.startKeepalive(); 65 + } 66 + 63 67 /// Get local db if ready (synced and available) 64 68 pub fn getLocalDb() ?*LocalDb { 65 69 if (local_db) |*l| {
+22
backend/src/db/Client.zig
··· 317 317 const max_len = 100; 318 318 return if (sql.len > max_len) sql[0..max_len] else sql; 319 319 } 320 + 321 + // --- keepalive --- 322 + 323 + const KEEPALIVE_INTERVAL_NS: u64 = 3 * 60 * std.time.ns_per_s; // 3 minutes 324 + 325 + pub fn startKeepalive(self: *Client) void { 326 + const thread = std.Thread.spawn(.{}, keepaliveLoop, .{self}) catch |err| { 327 + logfire.warn("turso: failed to start keepalive thread: {}", .{err}); 328 + return; 329 + }; 330 + thread.detach(); 331 + logfire.info("turso: keepalive started (interval=3m)", .{}); 332 + } 333 + 334 + fn keepaliveLoop(self: *Client) void { 335 + while (true) { 336 + std.Thread.sleep(KEEPALIVE_INTERVAL_NS); 337 + _ = self.exec("SELECT 1", .{}) catch |err| { 338 + logfire.debug("turso: keepalive ping failed: {}", .{err}); 339 + }; 340 + } 341 + }
+3
backend/src/main.zig
··· 90 90 tpuf.init(); 91 91 tpuf.startKeepalive(allocator); 92 92 93 + // keep turso connection warm (avoids ~1s TLS handshake on first query after idle) 94 + db.startKeepalive(); 95 + 93 96 // start reconciler (verifies documents still exist at source PDS) 94 97 ingest.reconciler.start(allocator); 95 98