╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Fork.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
82 const key = draftKey(existing.event.repo_id, existing.event.user_id); 83 try removeFromParentSet(DB, hash_kind, drafts, &key, &order_key); 84 } 85 } 86 } 87 88 const fork_cursor = try records.putCursor(fork_key); 89 try evt.upsert(Record, DB, hash_kind, try DB.HashMap(.read_write).init(fork_cursor), record); 90 try evt.indexEvent(DB, hash_kind, haxy_moment, event_id, .fork, record.created_order, record.removed); 91 92 const order_key = evt.orderKeyDesc(record.created_order, event_id); 93 if (existing_cursor_maybe == null) { 94 const ids = try DB.SortedSet(.read_write).init(try haxy_moment.putCursor(hash.hashInt(hash_kind, id_set_key))); 95 try ids.put(&order_key); 96 } 97 98 if (!record.removed) { 99 const by_user = try DB.SortedSet(.read_write).init(try user_forks.putCursor(hash.hashInt(hash_kind, record.event.user_id))); 100 try by_user.put(&order_key); 101 if (record.event.stage == .draft) { 102 const key = draftKey(record.event.repo_id, record.event.user_id); 103 const by_repo_user = try DB.SortedSet(.read_write).init(try drafts.putCursor(hash.hashInt(hash_kind, &key))); 104 try by_repo_user.put(&order_key); 105 } 106 } 107 } 108 109 fn removeFromParentSet( 110 comptime DB: type, 111 comptime hash_kind: hash.HashKind, 112 index: DB.HashMap(.read_write), 113 parent_id: []const u8, 114 order_key: *const [@sizeOf(u64) + evt.event_id_size]u8, 115 ) !void { 116 const cursor = try index.putCursor(hash.hashInt(hash_kind, parent_id)); 117 const ids = try DB.SortedSet(.read_write).init(cursor); 118 _ = try ids.remove(order_key); 119 } 120 121 pub fn readById( 122 comptime DB: type, 123 comptime hash_kind: hash.HashKind, 124 haxy_moment: DB.HashMap(.read_only), 125 arena: *std.heap.ArenaAllocator, 126 fork_id: []const u8, 127 ) !?Record { 128 const records_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, record_map_key)) orelse return null; 129 const records = try DB.HashMap(.read_only).init(records_cursor); 130 const fork_cursor = try records.getCursor(hash.hashInt(hash_kind, fork_id)) orelse return null; 131 return try evt.read(Record, DB, hash_kind, arena, try DB.HashMap(.read_only).init(fork_cursor)); 132 } 133