atproto relay implementation in zig zlay.waow.tech

refactor: remove warmCache, rely on multi-threaded on-demand resolver

the warmCache approach queued all 1.36M active DIDs — most of which
won't post for hours — competing with actually-active DIDs for resolver
time. the on-demand queue with 4 threads is a natural activity-weighted
priority queue that resolves exactly the right DIDs.

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

-25
-3
src/main.zig
··· 119 119 // start: loads active hosts from DB, spawns subscriber threads 120 120 try slurper.start(); 121 121 122 - // pre-populate resolver queue with all known active DIDs 123 - val.warmCache(&dp); 124 - 125 122 // start GC thread (runs every 10 minutes) 126 123 const gc_thread = try std.Thread.spawn(.{}, gcLoop, .{&dp}); 127 124
-22
src/validator.zig
··· 8 8 const std = @import("std"); 9 9 const zat = @import("zat"); 10 10 const broadcaster = @import("broadcaster.zig"); 11 - const event_log_mod = @import("event_log.zig"); 12 11 13 12 const Allocator = std.mem.Allocator; 14 13 const log = std.log.scoped(.relay); ··· 100 99 for (self.resolver_threads[0..count]) |*t| { 101 100 t.* = try std.Thread.spawn(.{}, resolveLoop, .{self}); 102 101 } 103 - } 104 - 105 - /// pre-populate the resolve queue with all active DIDs from the database. 106 - /// call after slurper.start() so subscribers are already running. 107 - pub fn warmCache(self: *Validator, persist: *event_log_mod.DiskPersist) void { 108 - var result = persist.db.query( 109 - "SELECT did FROM account WHERE status = 'active' AND upstream_status = 'active' ORDER BY uid ASC", 110 - .{}, 111 - ) catch |err| { 112 - log.warn("cache warming: query failed: {s}", .{@errorName(err)}); 113 - return; 114 - }; 115 - defer result.deinit(); 116 - 117 - var count: u64 = 0; 118 - while (result.nextUnsafe() catch null) |row| { 119 - const did = row.get([]const u8, 0); 120 - self.queueResolve(did); 121 - count += 1; 122 - } 123 - log.info("cache warming: queued {d} DIDs for resolution", .{count}); 124 102 } 125 103 126 104 /// validate a #sync frame: signature verification only (no ops, no MST).