╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Assignment.zig ───────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
152 const thread_id_bytes = evt.parseEventId(thread_id) catch return error.NotFound; 153 if (!try evt.threadHolds(repo_kind, repo_opts, io, allocator, repo, thread_kind, &thread_id_bytes, null)) return error.NotFound; 154 155 const id_bytes = idOf(&thread_id_bytes, email); 156 { 157 var arena = std.heap.ArenaAllocator.init(allocator); 158 defer arena.deinit(); 159 if (try evt.readFromRepo(Self, repo_kind, repo_opts, io, allocator, &arena, repo, &id_bytes)) |existing| { 160 if (!existing.removed) return error.AlreadyAssigned; 161 } 162 } 163 164 const event_id = std.fmt.bytesToHex(id_bytes, .lower); 165 try evt.consume(host, .repo, repo_kind, repo_opts, io, allocator, repo, evt.events_ref, &.{.{ 166 .id = event_id, 167 .timestamp = @intCast(std.Io.Timestamp.now(io, .real).toSeconds()), 168 .author = author, 169 .event = .{ .assign = .{ .thread_id = thread_id.*, .email = email } }, 170 }}); 171 return event_id; 172 } 173 174 // read an assignment by event id, or null if the id isn't a known assignment 175 pub fn readById( 176 comptime DB: type, 177 comptime hash_kind: hash.HashKind, 178 haxy_moment: DB.HashMap(.read_only), 179 arena: *std.heap.ArenaAllocator, 180 assignment_id: []const u8, 181 ) !?Record { 182 return try evt.readRecordSubset(Self, Record, DB, hash_kind, haxy_moment, arena, assignment_id); 183 } 184 185 // the emails assigned to a thread, oldest first 186 pub fn load( 187 comptime hash_kind: hash.HashKind, 188 arena: *std.heap.ArenaAllocator, 189 haxy_moment: evt.EventDB(hash_kind).HashMap(.read_only), 190 thread_id: []const u8, 191 ) ![]const []const u8 { 192 const DB = evt.EventDB(hash_kind); 193 var emails: std.ArrayList([]const u8) = .empty; 194 const index_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, thread_id_to_assignment_id_set_key)) orelse return emails.items; 195 const index = try DB.HashMap(.read_only).init(index_cursor); 196 const set_cursor = try index.getCursor(hash.hashInt(hash_kind, thread_id)) orelse return emails.items; 197 const set = try DB.SortedSet(.read_only).init(set_cursor); 198 199 var iter = try set.iteratorFromIndex(0); 200 while (try iter.next()) |kv_cursor| { 201 const id_bytes = try evt.readOrderKeyId(DB, kv_cursor); 202 const record = (try evt.readRecordSubset(Self, struct { event: struct { email: []const u8 } }, DB, hash_kind, haxy_moment, arena, &id_bytes)) orelse continue; 203 try emails.append(arena.allocator(), record.event.email); 204 } 205 return emails.items; 206 } 207