╭ changed ───────────────╮ │src/event/Attachment.zig│ ╰────────────────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭────────────────────────────────────────────────────────────────────────────────────╮ │ 4 const rp = xit.repo; │ │ 5 const hash = xit.hash; │ │ 6 │ │ 7 -parent_id: [evt.event_id_size * 2]u8, │ │ 7 +target_id: [evt.event_id_size * 2]u8, │ │ 8 │ │ 9 // what the db stores: the event's data plus the commit-derived fields. the file│ │10 // itself is the one entry in the event commit's tree, so its name and blob come│ ╰────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────╮ │26 pub const record_map_key = "event-id->attachment"; │ │27 pub const all_id_set_key = "attachment-id-set"; │ │28 │ │29 -// the index a parent event's view reads │ │30 -pub const parent_id_to_attachment_id_set_key = "parent-id->attachment-id-set";│ │29 +// the index a target event's view reads │ │30 +pub const target_id_to_attachment_id_set_key = "target-id->attachment-id-set";│ │31 │ │32 pub const max_size: usize = 10 * 1024 * 1024; │ │33 pub const name_max_len = 255; │ ╰──────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────╮ │42 return true; │ │43 } │ │44 │ │45 -fn parentExists( │ │45 +fn targetExists( │ │46 comptime DB: type, │ │47 comptime hash_kind: hash.HashKind,│ │48 haxy_moment: anytype, │ ╰──────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │49 - parent_id: *const [evt.event_id_size]u8, │ │49 + target_id: *const [evt.event_id_size]u8, │ │50 ) !bool { │ │51 const kinds_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, evt.event_index_key)) orelse return false;│ │52 const kinds = try DB.HashMap(.read_only).init(kinds_cursor); │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────╮ │53 - return try kinds.getCursor(hash.hashInt(hash_kind, parent_id)) != null;│ │53 + return try kinds.getCursor(hash.hashInt(hash_kind, target_id)) != null;│ │54 } │ │55 │ │56 pub fn consume( │ ╰───────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │67 const event_id_to_attachment_cursor = try haxy_moment.putCursor(hash.hashInt(hash_kind, record_map_key)); │ │68 const event_id_to_attachment = try DB.HashMap(.read_write).init(event_id_to_attachment_cursor); │ │69 │ │70 - const parent_id_to_attachment_id_set_cursor = try haxy_moment.putCursor(hash.hashInt(hash_kind, parent_id_to_attachment_id_set_key));│ │71 - const parent_id_to_attachment_id_set = try DB.HashMap(.read_write).init(parent_id_to_attachment_id_set_cursor); │ │70 + const target_id_to_attachment_id_set_cursor = try haxy_moment.putCursor(hash.hashInt(hash_kind, target_id_to_attachment_id_set_key));│ │71 + const target_id_to_attachment_id_set = try DB.HashMap(.read_write).init(target_id_to_attachment_id_set_cursor); │ │72 │ │73 var existing_record_maybe: ?Record = null; │ │74 const existing_cursor_maybe = try event_id_to_attachment.getCursor(attachment_key); │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │79 │ │80 var record_to_write = record_maybe orelse try evt.removedRecord(Record, DB, hash_kind, haxy_moment.readOnly(), existing_record_maybe);│ │81 │ │82 - const id_bytes = try evt.parseEventId(&record_to_write.event.parent_id); │ │83 - if (!try parentExists(DB, hash_kind, haxy_moment, &id_bytes)) return error.ParentNotFound; │ │82 + const target_id = try evt.parseEventId(&record_to_write.event.target_id); │ │83 + if (!try targetExists(DB, hash_kind, haxy_moment, &target_id)) return error.TargetNotFound; │ │84 if (!nameValid(record_to_write.name)) return error.InvalidAttachment; │ │85 │ │86 if (existing_record_maybe) |existing_record| { │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │91 record_to_write.name = existing_record.name; │ │92 record_to_write.blob_oid = existing_record.blob_oid; │ │93 │ │94 - // an attachment cannot move to another parent │ │95 - if (!std.mem.eql(u8, &existing_record.event.parent_id, &record_to_write.event.parent_id)) return error.ParentChanged;│ │94 + // an attachment cannot move to another target │ │95 + if (!std.mem.eql(u8, &existing_record.event.target_id, &record_to_write.event.target_id)) return error.TargetChanged;│ │96 } │ │97 │ │98 const attachment_cursor = try event_id_to_attachment.putCursor(attachment_key); │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │106 try attachment_id_set.put(&evt.orderKeyDesc(record_to_write.created_order, event_id)); │ │107 } │ │108 │ │109 - // removed attachments stay in the parent's set; the views skip them │ │110 - const parent_attachments_cursor = try parent_id_to_attachment_id_set.putCursor(hash.hashInt(hash_kind, &record_to_write.event.parent_id));│ │111 - const parent_attachments = try DB.SortedSet(.read_write).init(parent_attachments_cursor); │ │112 - try parent_attachments.put(&evt.orderKey(record_to_write.created_order, event_id)); │ │109 + // removed attachments stay in the target's set; the views skip them │ │110 + const target_attachments_cursor = try target_id_to_attachment_id_set.putCursor(hash.hashInt(hash_kind, &target_id)); │ │111 + const target_attachments = try DB.SortedSet(.read_write).init(target_attachments_cursor); │ │112 + try target_attachments.put(&evt.orderKey(record_to_write.created_order, event_id)); │ │113 } │ │114 │ │115 -// attach `blob` to a parent event and return the event id. `repo` must be │ │115 +// attach `blob` to a target event and return the event id. `repo` must be │ │116 // writable. │ │117 pub fn create( │ │118 host: evt.Host, │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────╮ │121 io: std.Io, │ │122 allocator: std.mem.Allocator, │ │123 repo: *rp.Repo(repo_kind, repo_opts), │ │124 - parent_kind: evt.EventKind, │ │125 - parent_id: *const [evt.event_id_size * 2]u8,│ │124 + target_kind: evt.EventKind, │ │125 + target_id: *const [evt.event_id_size * 2]u8,│ │126 blob: evt.Blob, │ │127 author: evt.CommitAuthor, │ │128 ) ![evt.event_id_size * 2]u8 { │ ╰─────────────────────────────────────────────────────╯ ╭──────╮ │next →│ ╰──────╯