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