╭ changed ─────────╮ │src/event/Repo.zig│ ╰──────────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭───────────────────────────────────────────────────────────╮ │19 event_id: *const [evt.event_id_size]u8, │ │20 event_maybe: ?@This(), │ │21 arena: *std.heap.ArenaAllocator, │ │22 + created_ts: u64, │ │23 ) !void { │ │24 const repo_key = hash.hashInt(hash_kind, event_id);│ │25 │ ╰───────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │54 │ │55 try name_to_repo_id.put(hash.hashInt(hash_kind, repo_path), .{ .bytes = event_id }); │ │56 │ │56 - // first time we've seen this repo: append its id to the ordered list │ │57 - // the repos view paginates through (a delete leaves a tombstone here). │ │57 + // first time we've seen this repo: record its creation timestamp and add it │ │58 + // to the ordered map the repos view paginates through │ │59 if (existing_cursor_maybe == null) { │ │59 - const repo_list_cursor = try haxy_moment.putCursor(hash.hashInt(hash_kind, "repo-list")); │ │60 - const repo_list = try DB.ArrayList(.read_write).init(repo_list_cursor); │ │61 - try repo_list.append(.{ .bytes = event_id }); │ │60 + try repo.put(hash.hashInt(hash_kind, "created-ts"), .{ .uint = created_ts }); │ │61 + │ │62 + const timestamp_to_repo_id_cursor = try haxy_moment.putCursor(hash.hashInt(hash_kind, "timestamp->repo-id"));│ │63 + const timestamp_to_repo_id = try DB.SortedMap(.read_write).init(timestamp_to_repo_id_cursor); │ │64 + const order_key = evt.orderKey(created_ts, event_id); │ │65 + try timestamp_to_repo_id.put(&order_key, .{ .bytes = event_id }); │ │66 } │ │67 │ │68 const user_id_to_repos_cursor = try haxy_moment.putCursor(hash.hashInt(hash_kind, "user-id->repos")); │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │79 const existing_path = try std.fmt.allocPrint(arena.allocator(), "{s}/{s}", .{ existing_repo_event.user_id, existing_repo_event.name });│ │80 _ = try name_to_repo_id.remove(hash.hashInt(hash_kind, existing_path)); │ │81 │ │82 + // drop it from the ordered map using its recorded creation timestamp │ │83 + if (try existing_repo.getCursor(hash.hashInt(hash_kind, "created-ts"))) |created_ts_cursor| { │ │84 + const stored_ts = try created_ts_cursor.readUint(); │ │85 + const timestamp_to_repo_id_cursor = try haxy_moment.putCursor(hash.hashInt(hash_kind, "timestamp->repo-id")); │ │86 + const timestamp_to_repo_id = try DB.SortedMap(.read_write).init(timestamp_to_repo_id_cursor); │ │87 + const order_key = evt.orderKey(stored_ts, event_id); │ │88 + _ = try timestamp_to_repo_id.remove(&order_key); │ │89 + } │ │90 + │ │91 const user_id_to_repos_cursor = try haxy_moment.putCursor(hash.hashInt(hash_kind, "user-id->repos")); │ │92 const user_id_to_repos = try DB.HashMap(.read_write).init(user_id_to_repos_cursor); │ │93 │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯