╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1 const std = @import("std"); 2 const evt = @import("../event.zig"); 3 const xit = @import("xit"); 4 const hash = xit.hash; 5 6 user_id: []const u8, 7 name: []const u8, 8 enable_issue: bool, 9 10 pub fn consume( 11 comptime DB: type, 12 comptime hash_kind: hash.HashKind, 13 haxy_moment: DB.HashMap(.read_write), 14 event_id: *const [evt.event_id_size]u8, 15 event_maybe: ?@This(), 16 arena: *std.heap.ArenaAllocator, 17 ) !void { 18 const repo_key = hash.hashInt(hash_kind, event_id); 19 20 const event_id_to_repo_cursor = try haxy_moment.putCursor(hash.hashInt(hash_kind, "event-id->repo")); 21 const event_id_to_repo = try DB.HashMap(.read_write).init(event_id_to_repo_cursor); 22 23 if (event_maybe) |event| { 24 const repo_cursor = try event_id_to_repo.putCursor(repo_key); 25 const repo = try DB.HashMap(.read_write).init(repo_cursor); 26 try evt.upsert(@This(), DB, hash_kind, repo, event); 27 28 const user_id_to_repos_cursor = try haxy_moment.putCursor(hash.hashInt(hash_kind, "user-id->repos")); 29 const user_id_to_repos = try DB.HashMap(.read_write).init(user_id_to_repos_cursor); 30 31 const user_repos_cursor = try user_id_to_repos.putCursor(hash.hashInt(hash_kind, event.user_id)); 32 const user_repos = try DB.CountedHashSet(.read_write).init(user_repos_cursor); 33 try user_repos.put(repo_key, .{ .bytes = event_id }); 34 } else { 35 if (try event_id_to_repo.getCursor(repo_key)) |existing_repo_cursor| { 36 const existing_repo = try DB.HashMap(.read_only).init(existing_repo_cursor); 37 const existing_repo_event = try evt.read(@This(), DB, hash_kind, arena, existing_repo); 38 39 const user_id_to_repos_cursor = try haxy_moment.putCursor(hash.hashInt(hash_kind, "user-id->repos")); 40 const user_id_to_repos = try DB.HashMap(.read_write).init(user_id_to_repos_cursor); 41 42 const user_key = hash.hashInt(hash_kind, existing_repo_event.user_id); 43 const user_repos_cursor = try user_id_to_repos.putCursor(user_key); 44 const user_repos = try DB.CountedHashSet(.read_write).init(user_repos_cursor); 45 _ = try user_repos.remove(repo_key); 46 } 47 if (!try event_id_to_repo.remove(repo_key)) return error.EventNotFound; 48 } 49 } 50