╭──────────╮ │← previous│ ╰──────────╯ ╭ changed ───────────────╮ │src/test/event/patch.zig│ ╰────────────────────────╯ ╭────────────────────────────────────────────────────────────╮ │975 + .repo_user_id = user_id, │ │976 .title = "explain the answer", │ │977 .labels = "documentation", │ │978 .description = "describes the existing answer",│ ╰────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────╮ │981 .timestamp = 3, │ │982 }); │ │983 defer allocator.free(unpushed_path); │ │976 - try pch.publish(repo_opts, io, allocator, &admin, &target, unpushed_path, .{ │ │984 + try pch.publish(repo_opts, io, allocator, &admin, &user_repo, &target, unpushed_path, .{│ │985 .id = unpushed_id_hex, │ │986 .user_id = user_id, │ │987 .repo_id = repo_id, │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1006 // edit the patch metadata in the fork │ │1007 // │ │1008 │ │1001 - try std.testing.expect(try pch.editDraft(repo_opts, io, allocator, &admin, draft_path, .{ │ │1009 + try std.testing.expect(try pch.editDraft(repo_opts, io, allocator, &admin, &user_repo, draft_path, .{│ │1010 .id = patch_id_hex, │ │1011 .user_id = user_id, │ │1012 .repo_id = repo_id, │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────╮ │1023 // │ │1024 │ │1025 const before_publish = try target.core.db.rootCursor().count(); │ │1018 - try pch.publish(repo_opts, io, allocator, &admin, &target, draft_path, .{ │ │1026 + try pch.publish(repo_opts, io, allocator, &admin, &user_repo, &target, draft_path, .{│ │1027 .id = patch_id_hex, │ │1028 .user_id = user_id, │ │1029 .repo_id = repo_id, │ ╰───────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────╮ │1031 .timestamp = 5, │ │1032 }); │ │1033 try std.testing.expectEqual(before_publish + 1, try target.core.db.rootCursor().count());│ │1026 - try pch.publish(repo_opts, io, allocator, &admin, &target, draft_path, .{ │ │1034 + try pch.publish(repo_opts, io, allocator, &admin, &user_repo, &target, draft_path, .{ │ │1035 .id = patch_id_hex, │ │1036 .user_id = user_id, │ │1037 .repo_id = repo_id, │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1049 try std.testing.expectEqual(null, try evt.PatchRev.readById(Repo.DB, repo_opts.hash, moment, &arena, &first_patchrev_id)); │ │1050 │ │1051 _ = arena.reset(.retain_capacity); │ │1044 - const admin_moment = try evt.currentMoment(evt.admin_repo_opts, &admin); │ │1045 - const published_fork = (try evt.Fork.readById(evt.AdminDB, evt.admin_repo_opts.hash, admin_moment, &arena, &patch_id)) orelse return error.NotFound;│ │1052 + const user_moment = try evt.currentMoment(evt.user_repo_opts, &user_repo); │ │1053 + const published_fork = (try evt.Fork.readById(evt.UserDB, evt.user_repo_opts.hash, user_moment, &arena, &patch_id)) orelse return error.NotFound; │ │1054 try std.testing.expect(!published_fork.removed); │ │1055 try std.testing.expectEqual(.publish, published_fork.event.stage); │ │1048 - const draft_key = evt.Fork.draftKey(&repo_id, &user_id); │ │1049 - try std.testing.expectEqual(0, try indexedForkCount(admin_moment, evt.Fork.repo_user_to_draft_id_set_key, &draft_key)); │ │1050 - try std.testing.expectEqual(2, try indexedForkCount(admin_moment, evt.Fork.user_id_to_fork_id_set_key, &user_id)); │ │1056 + try std.testing.expectEqual(0, try draftForkCount(user_moment, &repo_id)); │ │1057 + try std.testing.expectEqual(2, try activeForkCount(user_moment)); │ │1058 var squash_oid: [hash.hexLen(repo_opts.hash)]u8 = undefined; │ │1059 { │ │1060 var draft = try Repo.open(io, allocator, .{ .path = draft_path }); │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────╮ │1100 .squash => squash_oid, │ │1101 .source => source_oid, │ │1102 }; │ │1096 - try pch.mergeAndRemoveFork(repo_opts, io, allocator, repos_dir, &admin, &target, .{│ │1103 + try pch.mergeAndRemoveFork(repo_opts, io, allocator, repos_dir, &target, .{ │ │1104 .id = patch_id_hex, │ │1105 .revision = merge_revision, │ │1106 .author = author, │ ╰─────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1125 try std.testing.expect(null != try evt.PatchRev.readById(Repo.DB, repo_opts.hash, merged_moment, &arena, &first_patchrev_id)); │ │1126 │ │1127 _ = arena.reset(.retain_capacity); │ │1121 - const removed_fork = (try evt.Fork.readById(evt.AdminDB, evt.admin_repo_opts.hash, try evt.currentMoment(evt.admin_repo_opts, &admin), &arena, &patch_id)) orelse return error.NotFound; │ │1128 + const removed_fork = (try evt.Fork.readById(evt.UserDB, evt.user_repo_opts.hash, try evt.currentMoment(evt.user_repo_opts, &user_repo), &arena, &patch_id)) orelse return error.NotFound;│ │1129 try std.testing.expect(removed_fork.removed); │ │1130 } │ │1131 │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1125 -fn indexedForkCount( │ │1126 - moment: evt.AdminDB.HashMap(.read_only), │ │1127 - index_key: []const u8, │ │1128 - parent_id: []const u8, │ │1129 -) !u64 { │ │1130 - const index_cursor = try moment.getCursor(hash.hashInt(evt.admin_repo_opts.hash, index_key)) orelse return 0; │ │1131 - const index = try evt.AdminDB.HashMap(.read_only).init(index_cursor); │ │1132 - const ids_cursor = try index.getCursor(hash.hashInt(evt.admin_repo_opts.hash, parent_id)) orelse return 0; │ │1133 - const ids = try evt.AdminDB.SortedSet(.read_only).init(ids_cursor); │ │1132 +fn draftForkCount(moment: evt.UserDB.HashMap(.read_only), repo_id: []const u8) !u64 { │ │1133 + const index_cursor = try moment.getCursor(hash.hashInt(evt.user_repo_opts.hash, evt.Fork.repo_to_draft_id_set_key)) orelse return 0;│ │1134 + const index = try evt.UserDB.HashMap(.read_only).init(index_cursor); │ │1135 + const ids_cursor = try index.getCursor(hash.hashInt(evt.user_repo_opts.hash, repo_id)) orelse return 0; │ │1136 + const ids = try evt.UserDB.SortedSet(.read_only).init(ids_cursor); │ │1137 + return try ids.count(); │ │1138 +} │ │1139 + │ │1140 +fn activeForkCount(moment: evt.UserDB.HashMap(.read_only)) !u64 { │ │1141 + const ids_cursor = try moment.getCursor(hash.hashInt(evt.user_repo_opts.hash, evt.Fork.active_id_set_key)) orelse return 0; │ │1142 + const ids = try evt.UserDB.SortedSet(.read_only).init(ids_cursor); │ │1143 return try ids.count(); │ │1144 } │ │1145 │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭ changed ───────╮ │src/test/net.zig│ ╰────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │543 var arena = std.heap.ArenaAllocator.init(allocator); │ │544 defer arena.deinit(); │ │545 const moment = try evt.currentMoment(evt.admin_repo_opts, &admin); │ │546 - const target = (try evt.Repo.readByOwnerAndName(evt.AdminDB, evt.admin_repo_opts.hash, moment, &arena, "admin", "target")) orelse return error.NotFound;│ │546 + const target = (try evt.readRepoByOwnerAndName(io, allocator, &arena, moment, repos_dir, "admin", "target")) orelse return error.NotFound; │ │547 repo_id = target.event_id; │ │548 @memcpy(&user_id, target.repo.event.user_id); │ │549 - break :blk try fork.create(repo_opts, io, allocator, repos_dir, &admin, .{ │ │549 + var user_repo = (try evt.openUserRepo(io, allocator, repos_dir, &user_id)) orelse return error.NotFound; │ │550 + defer user_repo.deinit(io, allocator); │ │551 + break :blk try fork.create(repo_opts, io, allocator, repos_dir, &user_repo, .{ │ │552 .id = fork_id_hex, │ │553 .user_id = user_id, │ │554 .repo_id = repo_id, │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────╮ │next →│ ╰──────╯