Skip to content

Commit 426017b

Browse files
committed
Add segment count to GET /:index
1 parent d00987f commit 426017b

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

src/IndexReader.zig

+4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ pub fn getVersion(self: *Self) u64 {
6868
return 0;
6969
}
7070

71+
pub fn getSegmentCount(self: *Self) usize {
72+
return self.memory_segments.value.count() + self.file_segments.value.count();
73+
}
74+
7175
pub fn getAttributes(self: *Self, allocator: std.mem.Allocator) !std.StringHashMapUnmanaged(u64) {
7276
var attributes: std.StringHashMapUnmanaged(u64) = .{};
7377
errdefer attributes.deinit(allocator);

src/segment_list.zig

+4
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ pub fn SegmentList(Segment: type) type {
149149
return false;
150150
}
151151

152+
pub fn count(self: Self) usize {
153+
return self.nodes.items.len;
154+
}
155+
152156
pub fn getFirst(self: Self) ?Node {
153157
return if (self.nodes.items.len > 0) self.nodes.items[0] else null;
154158
}

src/server.zig

+2
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ const Attributes = struct {
412412

413413
const GetIndexResponse = struct {
414414
version: u64,
415+
segments: usize,
415416
attributes: Attributes,
416417

417418
pub fn msgpackFormat() msgpack.StructFormat {
@@ -428,6 +429,7 @@ fn handleGetIndex(ctx: *Context, req: *httpz.Request, res: *httpz.Response) !voi
428429

429430
const response = GetIndexResponse{
430431
.version = index_reader.getVersion(),
432+
.segments = index_reader.getSegmentCount(),
431433
.attributes = .{
432434
.attributes = try index_reader.getAttributes(req.arena),
433435
},

tests/test_index_api.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ def test_get_index(client, index_name, create_index, fmt):
3333
req = client.get(f'/{index_name}', headers=headers(fmt))
3434
assert req.status_code == 200, req.content
3535
if fmt == 'json':
36-
expected = {'version': 1, 'attributes': {'foo': 1234}}
36+
expected = {'version': 1, 'segments': 1, 'attributes': {'foo': 1234}}
3737
else:
38-
expected = {'v': 1, 'a': {'foo': 1234}}
38+
expected = {'v': 1, 's': 1, 'a': {'foo': 1234}}
3939
assert decode(fmt, req.content) == expected
4040

4141

0 commit comments

Comments
 (0)