gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit28e9c93828e9c938ticket list: draw the newest 50 rows and a Show more button (500 rows were a 2-4 s first paint, 740 KB, a 90 000 px phone page)mre28e9c938/lib/events.hl

8.6 KB

  1. // lib/events.hl — THE HISTORY OF A TICKET: an append-only event per change. Statics only, the server realm.
  2. // eventsTable pk @id index @ticket APPEND ONLY: { ticket (ticket @id), seq
  3. // (1, 2, … per ticket), kind, author, user?, text, from, to, created, oldId? }
  4. // kind = 'created' | 'comment' | 'state' | 'edit' | 'link' | 'assign'
  5. // 'assign' (ticket #20): { assignee (users @id, '' = unassigned), previous (users @id, '') }
  6. // 'link' (ticket #4, mission 017): { linkKind ('parent' | 'blockedBy'), action
  7. // ('set' | 'removed'), other, otherProject, otherNumber, previous?, previousProject?,
  8. // previousNumber? } — on the CHILD / the BLOCKED ticket (the one whose relation changed).
  9. // 'edit' (ticket #8, mission 014): { oldSubject, oldSummary, subject, summary } —
  10. // the values before AND after; the ticket record then carries the new ones.
  11. // `user` (users @id, users.hl) since ticket #7: the event's author is that
  12. // user's CURRENT display name; `author` keeps the name at writing time.
  13. // 'comment' (mission 016): the event keeps the FIRST text; edits, a deletion and likes are kept by
  14. // lib/comments.hl, and the rows here show the comment as it is now (commentStateOf). Its files
  15. // (tickets#27): lib/attachments.hl (the row's `attachments`).
  16. // tickets.hl writes the events (putEvent) together with the ticket record; this file shapes and reads them.
  17. import { MPackDB } from 'hl:mpackdb'
  18. import { storageDir, countOf, localStamp, ticketHref } from './util.hl'
  19. import { nameOfUser } from './users.hl'
  20. import { projectSlugOf } from './projects.hl'
  21. import { slugOf } from './tickets-helpers.hl'
  22. import { markdownBlocks } from './markdown.hl'
  23. import { commentStateOf, likersOf } from './comments.hl'
  24. import { attachmentsOf } from './attachments.hl'
  25. static eventsTable = new MPackDB(file = storageDir + '/events.db', primaryKey = '@id', indexes = ['@ticket'])
  26. // ---- writing -------------------------------------------------------------------------------------
  27. // appends one event record (built field by field by tickets.hl); answers its id, or null (eventsError says why)
  28. static putEvent = (rec) => { return eventsTable.put(rec) }
  29. static eventsError = () => { return eventsTable.lastError() }
  30. // one stored event record, or null (the event stream numbers it, lib/stream.hl)
  31. static eventRecord = (eventId) => { return eventId == null ? null : eventsTable.fetch(eventId) }
  32. // the API row of a stored event
  33. static eventRowAt = (eventId, t) => { return eventRowOf(eventsTable.fetch(eventId), t) }
  34. // ---- reading -------------------------------------------------------------------------------------
  35. // the history of a ticket (a record), oldest first: by stored time, then seq
  36. static historyOf = (t) => {
  37. out = []
  38. all = eventsTable.find('ticket', t.id)
  39. if (countOf(all) == 0) { return out }
  40. for (e of all) { out.push(eventRowOf(e, t)) }
  41. let i = 1
  42. while (i < out.length) {
  43. let cur = out[i]
  44. let j = i - 1
  45. while (j >= 0 && (out[j].createdMs > cur.createdMs || (out[j].createdMs == cur.createdMs && out[j].seq > cur.seq))) {
  46. out[j + 1] = out[j]
  47. j = j - 1
  48. }
  49. out[j + 1] = cur
  50. i = i + 1
  51. }
  52. return out
  53. }
  54. // a ticket from before the login has no createdBy: the free-text author of its 'created' event
  55. static creatorNameOf = (t) => {
  56. all = eventsTable.find('ticket', t.id)
  57. if (countOf(all) == 0) { return '' }
  58. for (e of all) { if (e.kind == 'created') { return e.author != null ? e.author : '' } }
  59. return ''
  60. }
  61. // ---- the shapes ----------------------------------------------------------------------------------
  62. static eventRowOf = (e, t) => {
  63. let kind = e.kind
  64. // computed BEFORE the literal: inside a literal that has an `id` entry, a called function's
  65. // parameter named `id` read that entry instead (mission 011, reported as a Hybriel issue)
  66. who = e.user != null ? nameOfUser(e.user) : e.author
  67. let label = kind == 'created' ? 'opened the ticket' : (kind == 'state' ? 'changed the state' : (kind == 'edit' ? 'edited the ticket' : 'commented'))
  68. if (kind == 'link') { label = linkLabelOf(e) }
  69. let assignedTo = ''
  70. let assignedWas = ''
  71. if (kind == 'assign') {
  72. assignedTo = e.assignee != null && e.assignee != '' ? nameOfUser(e.assignee) : ''
  73. assignedWas = e.previous != null && e.previous != '' ? nameOfUser(e.previous) : ''
  74. label = assignedTo != '' ? 'assigned the ticket to ' + assignedTo : 'unassigned the ticket' + (assignedWas != '' ? ' (was ' + assignedWas + ')' : '')
  75. }
  76. row = {
  77. id = e.id
  78. ticket = e.ticket
  79. project = t != null ? projectSlugOf(t) : ''
  80. number = t != null ? t.number : 0
  81. seq = e.seq != null ? e.seq : 0
  82. kind = kind
  83. author = who
  84. userId = e.user != null ? e.user : ''
  85. text = e.text != null ? e.text : ''
  86. hasText = e.text != null && e.text != ''
  87. from = e.from != null ? e.from : ''
  88. to = e.to != null ? e.to : ''
  89. toSlug = slugOf(e.to)
  90. isState = kind == 'state'
  91. isComment = kind == 'comment'
  92. isCreated = kind == 'created'
  93. label = label
  94. when = localStamp(e.created)
  95. createdMs = e.created
  96. }
  97. // ticket #8: only an edit event carries these (the JSON of every other event is unchanged)
  98. if (kind == 'edit') {
  99. row.isEdit = true
  100. row.oldSubject = e.oldSubject != null ? e.oldSubject : ''
  101. row.oldSummary = e.oldSummary != null ? e.oldSummary : ''
  102. row.newSubject = e.subject != null ? e.subject : ''
  103. row.newSummary = e.summary != null ? e.summary : ''
  104. row.subjectChanged = row.oldSubject != row.newSubject
  105. row.summaryChanged = row.oldSummary != row.newSummary
  106. }
  107. // ticket #4: only a link event carries these
  108. if (kind == 'link') {
  109. row.isLink = true
  110. row.linkKind = e.linkKind
  111. row.linkAction = e.action
  112. row.otherRef = e.otherProject + ' #' + e.otherNumber
  113. row.otherHref = ticketHref(e.otherProject, e.otherNumber)
  114. row.previousRef = e.previous != null ? e.previousProject + ' #' + e.previousNumber : ''
  115. }
  116. // mission 016: a comment as it is NOW (lib/comments.hl). Only a changed comment carries the extra keys: an edited one
  117. // `edited`, `editedWhen`, `earlier` ([{ when, text }], the versions before, oldest first) and the newest `text`; a
  118. // deleted one `deleted`, `deletedWhen`, no text, the label "commented (deleted …)"; a liked one `likes` (the count).
  119. // Every other comment row has exactly the keys it had before.
  120. if (kind == 'comment') {
  121. cs = commentStateOf(e)
  122. if (cs.edited) {
  123. row.text = cs.text
  124. row.hasText = cs.text != ''
  125. row.edited = true
  126. row.editedWhen = localStamp(cs.editedMs)
  127. row.earlier = versionsOf(cs.earlier)
  128. }
  129. if (cs.deleted) {
  130. row.text = ''
  131. row.hasText = false
  132. row.label = 'commented (deleted ' + localStamp(cs.deletedMs) + ')'
  133. row.deleted = true
  134. row.deletedWhen = localStamp(cs.deletedMs)
  135. }
  136. if (cs.likes > 0) { row.likes = cs.likes }
  137. // tickets#27: only a comment with files carries `attachments` ([{ id, name, type, size, image, url }]; a deleted one has none)
  138. if (!cs.deleted) {
  139. files = attachmentsOf(e.id)
  140. if (files.length > 0) { row.attachments = files }
  141. }
  142. }
  143. // ticket #20: only an assign event carries these
  144. if (kind == 'assign') {
  145. row.isAssign = true
  146. row.assignee = assignedTo
  147. row.previousAssignee = assignedWas
  148. }
  149. return row
  150. }
  151. static versionsOf = (list) => {
  152. out = []
  153. for (v of list) { out.push({ when = v.when text = v.text }) }
  154. return out
  155. }
  156. // "set the parent to ident.worldapi.org #1", "removed the blocker tickets.worldapi.org #6", …
  157. static linkLabelOf = (e) => {
  158. other = e.otherProject + ' #' + e.otherNumber
  159. if (e.linkKind == 'parent') {
  160. if (e.action == 'removed') { return 'removed the parent ' + other }
  161. was = e.previous != null ? ' (was ' + e.previousProject + ' #' + e.previousNumber + ')' : ''
  162. return 'set the parent to ' + other + was
  163. }
  164. if (e.action == 'removed') { return 'removed the blocker ' + other }
  165. return 'marked it blocked by ' + other
  166. }
  167. // THE PAGE'S EVENT ROW (ticket #6): the API row + its text as Markdown blocks (`md`), and for an
  168. // edit the previous summary's blocks (`oldSummaryMd`) and the new one's (`summaryMd`, the ticket
  169. // page takes it over live). Only pages and pushes carry these — the JSON API does not.
  170. static pageEventOf = (ev) => {
  171. out = {}
  172. for (k of ev.keys()) { out[k] = ev[k] }
  173. out.md = markdownBlocks(ev.text)
  174. // mission 016: who likes a comment (users @ids) — the page works out `liked` for the user looking
  175. if (ev.isComment == true) { out.likedBy = likersOf(ev.id) }
  176. if (ev.isEdit == true) {
  177. out.oldSummaryMd = markdownBlocks(ev.oldSummary)
  178. out.summaryMd = markdownBlocks(ev.newSummary)
  179. }
  180. return out
  181. }
  182. static pageEventsOf = (evs) => {
  183. out = []
  184. for (ev of evs) { out.push(pageEventOf(ev)) }
  185. return out
  186. }

Branches

Latest commits

  • 28e9c938ticket list: draw the newest 50 rows and a Show more button (500 rows were a 2-4 s first paint, 740 KB, a 90 000 px phone page)mre
  • ccebb0c7mobile: ticket number stays on one line, filter chips one scrolling row, fields full width under their caption, Edit/action buttons, member names whole, 44 px relation linksmre
  • f2dc7741gate: the phone toolbar is two even rows (E2)mre
  • 20f7c33async components.hybriel 214c318: MdEditor on a phone, two even toolbar rows of 44 px targets, label 15 px, table head 16 px (E2)mre
  • d74a5482sync components.hybriel 134b4e3: MdEditor builds an editor put into the page at once, redraws a surface put in anew (F5, hybriel#211)mre
  • 9d02c540sync components.hybriel 6b0936a: the 'edited' foldable drops the theme's border and marginmre
  • 22751914sync components.hybriel 8d79ff7: bubble hugs its content, quiet 'edited' label; gate checksmre
  • c8452453sync components 9a: shared Icon (icons/icons.hl), md-editor toolbar icons + single focus ring (components f4-icons ba96735)mre
  • 52ba11e8sync-components: copy icons/icons.hl + README (F4); testsmre
  • 138d198dmd-editor.hl: verbatim copy of components f3-mdvalue (an older text handed back is kept)mre
  • 18d2df60md-editor.hl: verbatim copy of components f3-mdvalue (an outside value change is shown by the editor)mre
  • f6764bedreports/H1-hydrate.mdmre
  • 1bbbf0edtests/browser.mjs: wait for hydration before clicking the login button on / (device B)mre
  • 6f503cfctests/cdp.mjs: HL_CPU_THROTTLE=<rate> optional CPU throttling for gate runsmre
  • e17e2855re-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
  • a6ddccd2re-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mre
  • 81e036b7docker-compose: nofile 65536 (Hybriel int 6+ boot opened >1024 files in the tracker)mre
  • 5d8d2cf6deploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre
  • 58e8c02cmission 024: report, LOG, STATUS, e2e fixmre
  • 50778073tests/e2e-route-marker.mjs: first paint marker, comments post/edit redrawmre