╭ changed ────╮ │src/event.zig│ ╰─────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭────────────────────────────────────────╮ │11 pub const event_id_size: usize = 32;│ │12 │ │13 pub const EventKind = enum { │ │14 + remove, │ │15 user, │ │16 repo, │ │17 issue, │ ╰────────────────────────────────────────╯ ╭────────────────────────────────────────────╮ │18 }; │ │19 │ │20 pub const EventData = union(EventKind) {│ │21 + remove: struct { │ │22 + event_kind: EventKind, │ │23 + }, │ │24 user: struct { │ │25 name: []const u8, │ │26 email: []const u8, │ ╰────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────╮ │45 kind: EventKind, │ │46 ) !EventData { │ │47 return switch (kind) { │ │48 + .remove => return error.InvalidEventKind, │ │49 .user => .{ │ │50 .user = .{ │ │51 .name = try readBytes(DB, hash_kind, allocator, map, "name"),│ ╰─────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │361 _ = try std.fmt.hexToBytes(&current_event_id, &event.id); │ │362 │ │363 switch (event.data) { │ │364 + .remove => |data| { │ │365 + const removed_key = hash.hashInt(repo_opts.hash, &current_event_id); │ │366 + switch (data.event_kind) { │ │367 + .remove => return error.InvalidRemoveKind, │ │368 + .user => { │ │369 + const event_id_to_user_cursor = try haxy_moment.putCursor(hash.hashInt(repo_opts.hash, "event-id->user")); │ │370 + const event_id_to_user = try DB.HashMap(.read_write).init(event_id_to_user_cursor); │ │371 + if (!try event_id_to_user.remove(removed_key)) return error.EventNotFound; │ │372 + │ │373 + const user_id_to_repos_cursor = try haxy_moment.putCursor(hash.hashInt(repo_opts.hash, "user-id->repos")); │ │374 + const user_id_to_repos = try DB.HashMap(.read_write).init(user_id_to_repos_cursor); │ │375 + _ = try user_id_to_repos.remove(removed_key); │ │376 + }, │ │377 + .repo => { │ │378 + const event_id_to_repo_cursor = try haxy_moment.putCursor(hash.hashInt(repo_opts.hash, "event-id->repo")); │ │379 + const event_id_to_repo = try DB.HashMap(.read_write).init(event_id_to_repo_cursor); │ │380 + │ │381 + if (try event_id_to_repo.getCursor(removed_key)) |existing_repo_cursor| { │ │382 + const existing_repo_map = try DB.HashMap(.read_only).init(existing_repo_cursor); │ │383 + const existing_repo = try EventData.read(DB, repo_opts.hash, arena.allocator(), existing_repo_map, .repo);│ │384 + const payload = existing_repo.repo; │ │385 + │ │386 + const user_id_to_repos_cursor = try haxy_moment.putCursor(hash.hashInt(repo_opts.hash, "user-id->repos"));│ │387 + const user_id_to_repos = try DB.HashMap(.read_write).init(user_id_to_repos_cursor); │ │388 + │ │389 + const user_key = hash.hashInt(repo_opts.hash, payload.user_id); │ │390 + const user_repos_cursor = try user_id_to_repos.putCursor(user_key); │ │391 + const user_repos = try DB.CountedHashSet(.read_write).init(user_repos_cursor); │ │392 + _ = try user_repos.remove(removed_key); │ │393 + } │ │394 + if (!try event_id_to_repo.remove(removed_key)) return error.EventNotFound; │ │395 + }, │ │396 + .issue => { │ │397 + const event_id_to_issue_cursor = try haxy_moment.putCursor(hash.hashInt(repo_opts.hash, "event-id->issue")); │ │398 + const event_id_to_issue = try DB.HashMap(.read_write).init(event_id_to_issue_cursor); │ │399 + if (!try event_id_to_issue.remove(removed_key)) return error.EventNotFound; │ │400 + }, │ │401 + } │ │402 + }, │ │403 .user => |data| { │ │404 const event_id_to_user_cursor = try haxy_moment.putCursor(hash.hashInt(repo_opts.hash, "event-id->user")); │ │405 const event_id_to_user = try DB.HashMap(.read_write).init(event_id_to_user_cursor); │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │406 │ │363 - const user_cursor = try event_id_to_user.putCursor(hash.hashInt(repo_opts.hash, &current_event_id));│ │407 + const user_key = hash.hashInt(repo_opts.hash, &current_event_id); │ │408 + const user_cursor = try event_id_to_user.putCursor(user_key); │ │409 const user_map = try DB.HashMap(.read_write).init(user_cursor); │ │365 - │ │410 try upsert(DB, repo_opts.hash, user_map, @TypeOf(data), data); │ │411 }, │ │412 .repo => |data| { │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │413 const event_id_to_repo_cursor = try haxy_moment.putCursor(hash.hashInt(repo_opts.hash, "event-id->repo"));│ │414 const event_id_to_repo = try DB.HashMap(.read_write).init(event_id_to_repo_cursor); │ │415 │ │372 - const repo_cursor = try event_id_to_repo.putCursor(hash.hashInt(repo_opts.hash, &current_event_id)); │ │416 + const repo_key = hash.hashInt(repo_opts.hash, &current_event_id); │ │417 + const repo_cursor = try event_id_to_repo.putCursor(repo_key); │ │418 const repo_map = try DB.HashMap(.read_write).init(repo_cursor); │ │374 - │ │419 try upsert(DB, repo_opts.hash, repo_map, @TypeOf(data), data); │ │420 │ │421 const user_id_to_repos_cursor = try haxy_moment.putCursor(hash.hashInt(repo_opts.hash, "user-id->repos"));│ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │423 │ │424 const user_repos_cursor = try user_id_to_repos.putCursor(hash.hashInt(repo_opts.hash, data.user_id)); │ │425 const user_repos = try DB.CountedHashSet(.read_write).init(user_repos_cursor); │ │382 - try user_repos.put(hash.hashInt(repo_opts.hash, &current_event_id), .{ .bytes = &current_event_id }); │ │426 + try user_repos.put(repo_key, .{ .bytes = &current_event_id }); │ │427 }, │ │428 .issue => |data| { │ │429 const event_id_to_issue_cursor = try haxy_moment.putCursor(hash.hashInt(repo_opts.hash, "event-id->issue"));│ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │430 const event_id_to_issue = try DB.HashMap(.read_write).init(event_id_to_issue_cursor); │ │431 │ │388 - const issue_cursor = try event_id_to_issue.putCursor(hash.hashInt(repo_opts.hash, &current_event_id));│ │432 + const issue_key = hash.hashInt(repo_opts.hash, &current_event_id); │ │433 + const issue_cursor = try event_id_to_issue.putCursor(issue_key); │ │434 const issue = try DB.HashMap(.read_write).init(issue_cursor); │ │390 - │ │435 try upsert(DB, repo_opts.hash, issue, @TypeOf(data), data); │ │436 }, │ │437 } │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯