╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ User.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
218 219 // a user's record map via the event-id->user index 220 fn userMap( 221 comptime DB: type, 222 comptime hash_kind: hash.HashKind, 223 haxy_moment: DB.HashMap(.read_only), 224 user_id: []const u8, 225 ) !?DB.HashMap(.read_only) { 226 const event_id_to_user_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, "event-id->user")) orelse return null; 227 const event_id_to_user = try DB.HashMap(.read_only).init(event_id_to_user_cursor); 228 const user_cursor = try event_id_to_user.getCursor(hash.hashInt(hash_kind, user_id)) orelse return null; 229 return try DB.HashMap(.read_only).init(user_cursor); 230 } 231 232 // read a user by name from the admin event store, or null if the admin repo or 233 // the user doesn't exist. field byte slices are allocated in `arena`. 234 pub fn readByName( 235 io: std.Io, 236 allocator: std.mem.Allocator, 237 admin_repo_path: []const u8, 238 arena: *std.heap.ArenaAllocator, 239 name: []const u8, 240 ) !?Record { 241 var repo = rp.Repo(.xit, evt.admin_repo_opts).open(io, allocator, .{ .path = admin_repo_path }) catch |err| switch (err) { 242 error.RepoNotFound => return null, 243 else => |e| return e, 244 }; 245 defer repo.deinit(io, allocator); 246 247 const moment = try evt.currentMoment(evt.admin_repo_opts, &repo); 248 249 const user_id = try readIdByName(evt.AdminDB, evt.admin_repo_opts.hash, moment, name) orelse return null; 250 251 return try readById(evt.AdminDB, evt.admin_repo_opts.hash, moment, arena, &user_id); 252 } 253