Skip to content

Commit 7cd3a35

Browse files
justrachclaude
andcommitted
Fix 3 compile errors in server.zig (Zig 0.15 compat)
1. @divTrunc for signed integer division (elapsed_ns / 1000) 2. Unwrap optional Doc before field access in time-travel GET 3. Pass allocator to cols.deinit(alloc) — Zig 0.15 ArrayList API Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent eaba9b0 commit 7cd3a35

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/server.zig

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pub const Server = struct {
136136

137137
fn recordQueryCost(self: *Server, tenant_id: []const u8, op: []const u8, rows_scanned: usize, bytes_read: usize, start_ns: i128) void {
138138
const elapsed_ns = std.time.nanoTimestamp() - start_ns;
139-
const cpu_us: u64 = @intCast(@max(elapsed_ns / 1000, 0));
139+
const cpu_us: u64 = @intCast(@max(@divTrunc(elapsed_ns, 1000), 0));
140140
const cost_nanos_usd: u64 = cpu_us * 5 + @as(u64, @intCast(rows_scanned)) + @as(u64, @intCast(bytes_read / 1024));
141141

142142
_ = self.query_count.fetchAdd(1, .monotonic);
@@ -313,7 +313,10 @@ fn handleGet(srv: *Server, tenant_id: []const u8, col_name: []const u8, key: []c
313313
const start_ns = std.time.nanoTimestamp();
314314
srv.db.recordTenantOperation(tenant_id) catch return err(429, "tenant ops quota exceeded");
315315
const col = srv.db.collectionForTenant(tenant_id, col_name) catch return err(500, "open collection failed");
316-
const d = if (as_of) |ts_ms| col.getAsOfTimestamp(key, ts_ms) else col.get(key) orelse return err(404, "not found");
316+
const d = if (as_of) |ts_ms|
317+
(col.getAsOfTimestamp(key, ts_ms) orelse return err(404, "not found"))
318+
else
319+
(col.get(key) orelse return err(404, "not found"));
317320
srv.recordQueryCost(tenant_id, "get", 1, d.key.len + d.value.len, start_ns);
318321

319322
// Write JSON body directly into resp_buf at offset 256 (reserve space for headers)
@@ -432,7 +435,7 @@ fn handleListCollections(srv: *Server, tenant_id: []const u8, alloc: std.mem.All
432435
var cols = srv.db.listCollectionsForTenant(tenant_id, alloc) catch return err(500, "list collections failed");
433436
defer {
434437
for (cols.items) |name| alloc.free(name);
435-
cols.deinit();
438+
cols.deinit(alloc);
436439
}
437440
var fbs = std.io.fixedBufferStream(getBodyBuf());
438441
const w = fbs.writer();

0 commit comments

Comments
 (0)