| 42 | 42 | | AND NOT (x.status = 'closed' AND COALESCE(x.u < cuts.lo, 0)) |
| 43 | 43 | | ), |
| 44 | 44 | | -- What each of them saw, as spans [t0, t1] (a moment where t0 = t1). |
| 45 | | − | -- CROSS JOIN keeps each read starting from the few candidates. |
| 46 | | − | act(pull_id, t0, t1) AS MATERIALIZED ( |
| 45 | + | -- CROSS JOIN keeps each read starting from the few candidates. D1 takes |
| 46 | + | -- at most five terms in one compound SELECT, so the sources are read in |
| 47 | + | -- two halves of four and joined. |
| 48 | + | act_a(pull_id, t0, t1) AS MATERIALIZED ( |
| 47 | 49 | | -- Comments of every kind: reviews, and the timeline's events (labels, |
| 48 | 50 | | -- assignees, review requests, milestones, ready, draft, closed, |
| 49 | 51 | | -- reopened, base changes, the merge queue, auto-merge, branches deleted |
| ⋯ |
| 57 | 59 | | -- Its acceptance checks, from queued to finished. |
| 58 | 60 | | UNION ALL SELECT k.id, julianday(cr.created_at), julianday(COALESCE(cr.finished_at, cr.created_at)) |
| 59 | 61 | | FROM cand k CROSS JOIN check_runs cr ON cr.pull_id = k.id |
| 62 | + | ), |
| 63 | + | act_b(pull_id, t0, t1) AS MATERIALIZED ( |
| 60 | 64 | | -- Statuses and check runs on its head commit, the one commit pulls keep |
| 61 | 65 | | -- (a status keeps only when it last changed). |
| 62 | | − | UNION ALL SELECT k.id, julianday(st.updated_at), julianday(st.updated_at) |
| 66 | + | SELECT k.id, julianday(st.updated_at), julianday(st.updated_at) |
| 63 | 67 | | FROM cand k CROSS JOIN commit_statuses st ON st.repo_id = k.repo_id AND st.sha = k.head_commit |
| 64 | 68 | | UNION ALL SELECT k.id, julianday(ck.created_at), julianday(ck.updated_at) |
| 65 | 69 | | FROM cand k CROSS JOIN commit_check_runs ck ON ck.repo_id = k.repo_id AND ck.head_sha = k.head_commit |
| ⋯ |
| 70 | 74 | | UNION ALL SELECT k.id, julianday(s.started_at), julianday(s.last_seen_at) |
| 71 | 75 | | FROM cand k CROSS JOIN tied t ON t.pull_id = k.id CROSS JOIN sessions s ON s.parent_id = t.session_id |
| 72 | 76 | | ), |
| 77 | + | act(pull_id, t0, t1) AS (SELECT * FROM act_a UNION ALL SELECT * FROM act_b), |
| 73 | 78 | | -- Each week a pull request saw something in the three days before its cut. |
| 74 | 79 | | busy AS MATERIALIZED ( |
| 75 | 80 | | SELECT DISTINCT a.pull_id, w.start FROM act a JOIN w ON a.t0 < w.cut AND a.t1 >= w.cut - 3 |