|
289 | 289 | n (parse-version-number new-version)] |
290 | 290 | (when (and n (>= n 1)) |
291 | 291 | (let [versions-to-close (cond-> #{new-version} |
292 | | - (> n 1) (conj (str "v" (dec n))))] |
293 | | - (doseq [rid nearest-report-eids] |
294 | | - ;; Refresh the snapshot per-iteration so prior transacts in |
295 | | - ;; this loop are visible to the :report/closed check below. |
296 | | - (let [r (d/pull (d/db conn) |
297 | | - [:report/type :report/version :report/topic-value :report/closed |
298 | | - :report/message-id] |
299 | | - rid)] |
300 | | - (when (and (= :patch (:report/type r)) |
301 | | - (contains? versions-to-close (:report/version r)) |
302 | | - (not (:report/closed r)) |
303 | | - (or (and (nil? new-topic) (nil? (:report/topic-value r))) |
304 | | - (and new-topic |
305 | | - (= (str/lower-case new-topic) |
306 | | - (str/lower-case (or (:report/topic-value r) "")))))) |
307 | | - (auto-supersede-patch! |
308 | | - conn rid report-eid email |
309 | | - (str "[PATCH " (:report/version r) |
310 | | - (when-let [t (:report/topic-value r)] (str " " t)) "] " |
311 | | - "(" (:report/message-id r) ") " |
312 | | - "(superseded by " new-version ")"))))))))) |
| 292 | + (> n 1) (conj (str "v" (dec n)))) |
| 293 | + new-topic-lc (some-> new-topic str/lower-case) |
| 294 | + ;; Single snapshot: nearest-report-eids contains distinct |
| 295 | + ;; rids and the daemon is single-threaded on this section, |
| 296 | + ;; so no concurrent mutation of :report/closed can happen |
| 297 | + ;; between pulls. If that invariant changes, restore the |
| 298 | + ;; per-iteration refresh. |
| 299 | + db (d/db conn) |
| 300 | + candidates (keep |
| 301 | + (fn [rid] |
| 302 | + (let [r (d/pull db |
| 303 | + [:report/type :report/version |
| 304 | + :report/topic-value :report/closed |
| 305 | + :report/message-id] |
| 306 | + rid)] |
| 307 | + (when (and (= :patch (:report/type r)) |
| 308 | + (contains? versions-to-close |
| 309 | + (:report/version r)) |
| 310 | + (not (:report/closed r)) |
| 311 | + (= new-topic-lc |
| 312 | + (some-> (:report/topic-value r) |
| 313 | + str/lower-case))) |
| 314 | + [rid r]))) |
| 315 | + nearest-report-eids)] |
| 316 | + (doseq [[rid r] candidates] |
| 317 | + (auto-supersede-patch! |
| 318 | + conn rid report-eid email |
| 319 | + (str "[PATCH " (:report/version r) |
| 320 | + (when-let [t (:report/topic-value r)] (str " " t)) "] " |
| 321 | + "(" (:report/message-id r) ") " |
| 322 | + "(superseded by " new-version ")"))))))) |
313 | 323 |
|
314 | 324 | (defn- normalize-subject |
315 | 325 | "Strip Re:/Fwd: prefixes and bracketed tags to get the base subject." |
|
547 | 557 | email-eid (:db/id email) |
548 | 558 | from-addr (:email/author-address email) |
549 | 559 | addr-lc (some-> from-addr str/lower-case) |
550 | | - targets (rel/active-targets db patch-report-eid :resolves)] |
| 560 | + targets (rel/active-targets db patch-report-eid :resolves) |
| 561 | + patch-mid (:report/message-id |
| 562 | + (d/pull db [:report/message-id] patch-report-eid))] |
551 | 563 | (doseq [bug-eid targets] |
552 | | - (let [bug-state (d/pull db [:report/acked :report/owned] bug-eid) |
| 564 | + (let [bug-state (d/pull db [:report/acked :report/owned :report/message-id] bug-eid) |
553 | 565 | credit (fn [tx attr addr-attr] |
554 | 566 | (cond-> tx |
555 | 567 | (nil? (get bug-state attr)) |
|
561 | 573 | (d/transact! conn tx) |
562 | 574 | (tracking/bump-report-updated! conn bug-eid) |
563 | 575 | (log/info "Auto-credit:" from-addr "credited as acked+owned of" |
564 | | - (:report/message-id (d/pull (d/db conn) [:report/message-id] bug-eid)) |
565 | | - "via patch" |
566 | | - (:report/message-id (d/pull (d/db conn) [:report/message-id] patch-report-eid)))))))) |
| 576 | + (:report/message-id bug-state) |
| 577 | + "via patch" patch-mid)))))) |
567 | 578 |
|
568 | 579 | (defn- run-post-creation-hooks! |
569 | 580 | "Execute post-creation side effects driven by the plan." |
|
0 commit comments