╭ changed ─────────╮ │src/event/User.zig│ ╰──────────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭─────────────────────────────────────────────────────────────────────────────────╮ │17 removed: bool = false, │ │18 created_order: u64 = 0, │ │19 updated_order: u64 = 0, │ │20 - │ │21 - // a user's key in the name index │ │22 - pub fn indexKey(self: Record, allocator: std.mem.Allocator) ![]const u8 {│ │23 - _ = allocator; │ │24 - return self.event.name; │ │25 - } │ │20 }; │ │21 │ │22 // the subset of a user that anyone may see │ ╰─────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │118 try active.put(&order_key); │ │119 try name_to_user_id.put(hash.hashInt(hash_kind, record_to_write.event.name), .{ .bytes = event_id }); │ │120 try email_to_user_id.put(hash.hashInt(hash_kind, record_to_write.event.email), .{ .bytes = event_id }); │ │127 - } │ │128 - │ │129 - const became_removed = record_to_write.removed and if (existing_record_maybe) |existing| !existing.removed else true;│ │130 - if (became_removed) { │ │131 - // the user's repos go with them: the repo name index is keyed by owner │ │132 - // id, so one left behind is listed but can never be resolved again │ │133 - const user_id_to_repo_id_set_cursor = try haxy_moment.putCursor(hash.hashInt(hash_kind, "user-id->repo-id-set"));│ │134 - const user_id_to_repo_id_set = try DB.HashMap(.read_write).init(user_id_to_repo_id_set_cursor); │ │135 - if (try user_id_to_repo_id_set.getCursor(user_key)) |user_repos_cursor| { │ │136 - const user_repos = try DB.SortedSet(.read_only).init(user_repos_cursor); │ │137 - │ │138 - // collected up front, since removing a repo removes it from this set │ │139 - var repo_ids: std.ArrayList([evt.event_id_size]u8) = .empty; │ │140 - var repo_iter = try user_repos.iteratorFromIndex(0); │ │141 - while (try repo_iter.next()) |kv_pair_cursor| { │ │142 - try repo_ids.append(arena.allocator(), try evt.readOrderKeyId(DB, kv_pair_cursor)); │ │143 - } │ │144 - │ │145 - for (repo_ids.items) |*repo_id| { │ │146 - try evt.Repo.consume(DB, hash_kind, haxy_moment, repo_id, null, arena, null); │ │147 - } │ │148 - } │ │149 - _ = try user_id_to_repo_id_set.remove(user_key); │ │121 } │ │122 } │ │123 │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │203 const user_map = try userMap(DB, hash_kind, haxy_moment, &user_id) orelse return null; │ │204 const record = try evt.read(struct { event: Public }, DB, hash_kind, arena, user_map); │ │205 return record.event; │ │206 +} │ │207 + │ │208 +// a user's id via the name->user-id index │ │209 +pub fn readIdByName( │ │210 + comptime DB: type, │ │211 + comptime hash_kind: hash.HashKind, │ │212 + haxy_moment: DB.HashMap(.read_only), │ │213 + name: []const u8, │ │214 +) !?[evt.event_id_size]u8 { │ │215 + return try readIdFromIndex(DB, hash_kind, haxy_moment, name_index_key, name); │ │216 +} │ │217 + │ │218 +// a user's id via the email->user-id index │ │219 +pub fn readIdByEmail( │ │220 + comptime DB: type, │ │221 + comptime hash_kind: hash.HashKind, │ │222 + haxy_moment: DB.HashMap(.read_only), │ │223 + email: []const u8, │ │224 +) !?[evt.event_id_size]u8 { │ │225 + return try readIdFromIndex(DB, hash_kind, haxy_moment, email_to_user_id_key, email); │ │226 +} │ │227 + │ │228 +fn readIdFromIndex( │ │229 + comptime DB: type, │ │230 + comptime hash_kind: hash.HashKind, │ │231 + haxy_moment: DB.HashMap(.read_only), │ │232 + index_key: []const u8, │ │233 + key: []const u8, │ │234 +) !?[evt.event_id_size]u8 { │ │235 + const index_cursor = (try haxy_moment.getCursor(hash.hashInt(hash_kind, index_key))) orelse return null;│ │236 + const index = try DB.HashMap(.read_only).init(index_cursor); │ │237 + const user_id_cursor = (try index.getCursor(hash.hashInt(hash_kind, key))) orelse return null; │ │238 + var user_id: [evt.event_id_size]u8 = undefined; │ │239 + _ = try user_id_cursor.readBytes(&user_id); │ │240 + return user_id; │ │241 } │ │242 │ │243 // a user's record map via the event-id->user index │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯