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.

feat: add embeddings count to stats endpoint

zzstoatzz 7f49b5ea 8e45d1ed

+14 -9
+1 -1
backend/src/server.zig
··· 153 153 var response: std.ArrayList(u8) = .{}; 154 154 defer response.deinit(alloc); 155 155 156 - try response.print(alloc, "{{\"documents\":{d},\"publications\":{d},\"cache_hits\":{d},\"cache_misses\":{d}}}", .{ db_stats.documents, db_stats.publications, db_stats.cache_hits, db_stats.cache_misses }); 156 + try response.print(alloc, "{{\"documents\":{d},\"publications\":{d},\"embeddings\":{d},\"cache_hits\":{d},\"cache_misses\":{d}}}", .{ db_stats.documents, db_stats.publications, db_stats.embeddings, db_stats.cache_hits, db_stats.cache_misses }); 157 157 158 158 try sendJson(request, response.items); 159 159 }
+13 -8
backend/src/stats.zig
··· 38 38 pub const Stats = struct { 39 39 documents: i64, 40 40 publications: i64, 41 + embeddings: i64, 41 42 searches: i64, 42 43 errors: i64, 43 44 started_at: i64, 44 45 cache_hits: i64, 45 46 cache_misses: i64, 46 47 }; 48 + 49 + const default_stats: Stats = .{ .documents = 0, .publications = 0, .embeddings = 0, .searches = 0, .errors = 0, .started_at = 0, .cache_hits = 0, .cache_misses = 0 }; 47 50 48 51 pub fn getStats() Stats { 49 - const c = db.getClient() orelse return .{ .documents = 0, .publications = 0, .searches = 0, .errors = 0, .started_at = 0, .cache_hits = 0, .cache_misses = 0 }; 52 + const c = db.getClient() orelse return default_stats; 50 53 51 54 var res = c.query( 52 55 \\SELECT 53 56 \\ (SELECT COUNT(*) FROM documents) as docs, 54 57 \\ (SELECT COUNT(*) FROM publications) as pubs, 58 + \\ (SELECT COUNT(*) FROM documents WHERE embedding IS NOT NULL) as embeddings, 55 59 \\ (SELECT total_searches FROM stats WHERE id = 1) as searches, 56 60 \\ (SELECT total_errors FROM stats WHERE id = 1) as errors, 57 61 \\ (SELECT service_started_at FROM stats WHERE id = 1) as started_at, 58 62 \\ (SELECT COALESCE(cache_hits, 0) FROM stats WHERE id = 1) as cache_hits, 59 63 \\ (SELECT COALESCE(cache_misses, 0) FROM stats WHERE id = 1) as cache_misses 60 - , &.{}) catch return .{ .documents = 0, .publications = 0, .searches = 0, .errors = 0, .started_at = 0, .cache_hits = 0, .cache_misses = 0 }; 64 + , &.{}) catch return default_stats; 61 65 defer res.deinit(); 62 66 63 - const row = res.first() orelse return .{ .documents = 0, .publications = 0, .searches = 0, .errors = 0, .started_at = 0, .cache_hits = 0, .cache_misses = 0 }; 67 + const row = res.first() orelse return default_stats; 64 68 return .{ 65 69 .documents = row.int(0), 66 70 .publications = row.int(1), 67 - .searches = row.int(2), 68 - .errors = row.int(3), 69 - .started_at = row.int(4), 70 - .cache_hits = row.int(5), 71 - .cache_misses = row.int(6), 71 + .embeddings = row.int(2), 72 + .searches = row.int(3), 73 + .errors = row.int(4), 74 + .started_at = row.int(5), 75 + .cache_hits = row.int(6), 76 + .cache_misses = row.int(7), 72 77 }; 73 78 } 74 79