╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ User.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
310 311 // a user's record map via the event-id->user index 312 fn userMap( 313 comptime DB: type, 314 comptime hash_kind: hash.HashKind, 315 haxy_moment: DB.HashMap(.read_only), 316 user_id: []const u8, 317 ) !?DB.HashMap(.read_only) { 318 const event_id_to_user_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, "event-id->user")) orelse return null; 319 const event_id_to_user = try DB.HashMap(.read_only).init(event_id_to_user_cursor); 320 const user_cursor = try event_id_to_user.getCursor(hash.hashInt(hash_kind, user_id)) orelse return null; 321 return try DB.HashMap(.read_only).init(user_cursor); 322 } 323 324 // read a user by name from the admin event store, or null if the admin repo or 325 // the user doesn't exist. field byte slices are allocated in `arena`. 326 pub fn readByName( 327 io: std.Io, 328 allocator: std.mem.Allocator, 329 admin_repo_path: []const u8, 330 arena: *std.heap.ArenaAllocator, 331 name: []const u8, 332 ) !?Record { 333 var repo = rp.Repo(.xit, evt.admin_repo_opts).open(io, allocator, .{ .path = admin_repo_path }) catch |err| switch (err) { 334 error.RepoNotFound => return null, 335 else => |e| return e, 336 }; 337 defer repo.deinit(io, allocator); 338 339 const moment = try evt.currentMoment(evt.admin_repo_opts, &repo); 340 341 const user_id = try readIdByName(evt.AdminDB, evt.admin_repo_opts.hash, moment, name) orelse return null; 342 343 return try readById(evt.AdminDB, evt.admin_repo_opts.hash, moment, arena, &user_id); 344 } 345