fix: limit ripgrep processing to 1000 lines of output

More is not really useful and potentially very laggy.
This commit is contained in:
CJ van den Berg 2024-12-06 21:07:14 +01:00
parent 3b4687761e
commit cf2b9c76ed
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -161,16 +161,23 @@ const Process = struct {
fn handle_terminated(self: *Process) !void { fn handle_terminated(self: *Process) !void {
const output = try self.output.toOwnedSlice(); const output = try self.output.toOwnedSlice();
var count: usize = 0;
var it = std.mem.splitScalar(u8, output, '\n'); var it = std.mem.splitScalar(u8, output, '\n');
while (it.next()) |json| { while (it.next()) |json| {
if (json.len == 0) continue; if (json.len == 0) continue;
var msg_buf: [tp.max_message_size]u8 = undefined; var msg_buf: [tp.max_message_size]u8 = undefined;
const msg: tp.message = .{ .buf = try cbor.fromJson(json, &msg_buf) }; const msg: tp.message = .{ .buf = try cbor.fromJson(json, &msg_buf) };
try self.dispatch(msg); try self.dispatch(msg);
count += 1;
if (count > 1000) break;
} }
try self.parent.send(.{ self.tag, "done" }); try self.parent.send(.{ self.tag, "done" });
if (count > 1000) {
self.logger.print("found more than {d} matches", .{self.match_count});
} else {
self.logger.print("found {d} matches", .{self.match_count}); self.logger.print("found {d} matches", .{self.match_count});
} }
}
fn dispatch(self: *Process, m: tp.message) !void { fn dispatch(self: *Process, m: tp.message) !void {
var obj = std.json.ObjectMap.init(self.allocator); var obj = std.json.ObjectMap.init(self.allocator);