spur-board 0.63.0 → 0.63.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/daemon.mjs
CHANGED
|
@@ -12422,6 +12422,22 @@ async function savePrPolling(trx, source, fact, recheckAt, preserve = false) {
|
|
|
12422
12422
|
value
|
|
12423
12423
|
}).onConflict((oc) => preserve ? oc.column("key").doNothing() : oc.column("key").doUpdateSet({ value })).execute();
|
|
12424
12424
|
}
|
|
12425
|
+
/**
|
|
12426
|
+
* Replaces the ticket keys `source` last read for a PR in the `pr_ticket_key` candidate index.
|
|
12427
|
+
* `repo` is the snapshot's stored casing. Call it wherever a source writes a snapshot's details
|
|
12428
|
+
* or its polling ticket keys from a fresh read; today that is only pr() in observe.ts.
|
|
12429
|
+
*/
|
|
12430
|
+
async function replacePrTicketKeys(trx, source, repo, number, keys) {
|
|
12431
|
+
await trx.deleteFrom("pr_ticket_key").where("repo", "=", repo).where("number", "=", number).where("source", "=", source).execute();
|
|
12432
|
+
const unique = [...new Set(keys)];
|
|
12433
|
+
if (unique.length === 0) return;
|
|
12434
|
+
await trx.insertInto("pr_ticket_key").values(unique.map((ticket_key) => ({
|
|
12435
|
+
repo,
|
|
12436
|
+
number,
|
|
12437
|
+
source,
|
|
12438
|
+
ticket_key
|
|
12439
|
+
}))).execute();
|
|
12440
|
+
}
|
|
12425
12441
|
/** The PR was merged before the reopen; a tie counts the merge. */
|
|
12426
12442
|
function mergedBefore(fact, reopenedAt) {
|
|
12427
12443
|
return fact.state === "merged" && reopenedAt !== null && Date.parse(fact.mergedAt ?? fact.updatedAt) < Date.parse(reopenedAt);
|
|
@@ -12461,7 +12477,7 @@ async function reconcileTaskPrs(trx, config, taskId, at) {
|
|
|
12461
12477
|
if (task.membership === "archived" || task.manual_exclude === 1) return;
|
|
12462
12478
|
const project = config.projects.find((entry) => entry.id === task.project);
|
|
12463
12479
|
if (project === void 0) return;
|
|
12464
|
-
const snapshots = await trx.selectFrom("pr_snapshot").selectAll().execute();
|
|
12480
|
+
const snapshots = await trx.selectFrom("pr_ticket_key").innerJoin("pr_snapshot", (join) => join.onRef("pr_snapshot.repo", "=", "pr_ticket_key.repo").onRef("pr_snapshot.number", "=", "pr_ticket_key.number")).selectAll("pr_snapshot").distinct().where("pr_ticket_key.ticket_key", "=", task.key).where("pr_ticket_key.source", "in", project.repos.map((repo) => prSourceId(project.id, repo))).orderBy(sql`pr_snapshot.rowid`).execute();
|
|
12465
12481
|
for (const row of snapshots) {
|
|
12466
12482
|
const repo = project.repos.find((repo) => repo.toLowerCase() === row.repo.toLowerCase());
|
|
12467
12483
|
if (repo === void 0) continue;
|
|
@@ -17011,6 +17027,7 @@ async function pr(trx, config, fact, at, source) {
|
|
|
17011
17027
|
source,
|
|
17012
17028
|
observed_at: at
|
|
17013
17029
|
})).execute();
|
|
17030
|
+
await replacePrTicketKeys(trx, source, old?.repo ?? fact.repo, fact.number, fact.ticketKeys);
|
|
17014
17031
|
if (old !== void 0 && old.head_sha.toLowerCase() !== fact.headSha.toLowerCase()) await voidMarksOffHead(trx, {
|
|
17015
17032
|
repo: fact.repo,
|
|
17016
17033
|
number: fact.number,
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
-- Candidate index of the ticket keys each source last read for a PR, so a task added after its PR
|
|
2
|
+
-- finds the PR without reading every retained snapshot. It may hold stale extras: reconcileTaskPrs
|
|
3
|
+
-- re-checks each candidate against the snapshot and the source's polling state. Only pr() in
|
|
4
|
+
-- observe.ts writes snapshot details and polling keys; a new writer must keep this table current.
|
|
5
|
+
CREATE TABLE pr_ticket_key (
|
|
6
|
+
repo TEXT NOT NULL,
|
|
7
|
+
number INTEGER NOT NULL,
|
|
8
|
+
source TEXT NOT NULL,
|
|
9
|
+
ticket_key TEXT NOT NULL,
|
|
10
|
+
PRIMARY KEY (repo, number, source, ticket_key),
|
|
11
|
+
FOREIGN KEY (repo, number) REFERENCES pr_snapshot (repo, number) ON DELETE CASCADE
|
|
12
|
+
) STRICT;
|
|
13
|
+
CREATE INDEX pr_ticket_key_lookup ON pr_ticket_key (ticket_key, source);
|
|
14
|
+
|
|
15
|
+
-- Each snapshot's keys under the source that wrote it. CASE keeps malformed JSON out of json_each.
|
|
16
|
+
INSERT OR IGNORE INTO pr_ticket_key (repo, number, source, ticket_key)
|
|
17
|
+
SELECT s.repo, s.number, s.source, k.value
|
|
18
|
+
FROM pr_snapshot s,
|
|
19
|
+
json_each(
|
|
20
|
+
CASE WHEN json_valid(s.detail) THEN
|
|
21
|
+
CASE WHEN json_type(s.detail, '$.ticketKeys') = 'array' THEN s.detail END
|
|
22
|
+
END,
|
|
23
|
+
'$.ticketKeys'
|
|
24
|
+
) k
|
|
25
|
+
WHERE k.type = 'text';
|
|
26
|
+
|
|
27
|
+
-- Keys other sources saved in their polling state ('pr-poll:<source>:pr:<lower repo>#<number>').
|
|
28
|
+
-- Each key is parsed once and joined through a temporary index on the lowercased snapshot
|
|
29
|
+
-- identity, so the backfill does not compare every polling key with every snapshot. Repo names
|
|
30
|
+
-- hold no ':' or '#', so the repo is the text after the last ':' and the number follows the '#'.
|
|
31
|
+
CREATE INDEX pr_snapshot_lower_identity ON pr_snapshot (lower(repo), number);
|
|
32
|
+
|
|
33
|
+
INSERT OR IGNORE INTO pr_ticket_key (repo, number, source, ticket_key)
|
|
34
|
+
SELECT s.repo, s.number, p.source, k.value
|
|
35
|
+
FROM (
|
|
36
|
+
SELECT value,
|
|
37
|
+
substr(prefix, 1, length(prefix) - 4) AS source,
|
|
38
|
+
substr(head, length(prefix) + 1, length(head) - length(prefix) - 1) AS repo,
|
|
39
|
+
CAST(digits AS INTEGER) AS number
|
|
40
|
+
FROM (
|
|
41
|
+
SELECT value, head, digits,
|
|
42
|
+
rtrim(head, replace(head, ':', '')) AS prefix
|
|
43
|
+
FROM (
|
|
44
|
+
SELECT value, head, substr(rest, length(head) + 1) AS digits
|
|
45
|
+
FROM (
|
|
46
|
+
SELECT value, rest, rtrim(rest, '0123456789') AS head
|
|
47
|
+
FROM (SELECT value, substr(key, 9) AS rest FROM meta WHERE key GLOB 'pr-poll:*')
|
|
48
|
+
)
|
|
49
|
+
)
|
|
50
|
+
)
|
|
51
|
+
WHERE head GLOB '*#' AND digits <> '' AND CAST(CAST(digits AS INTEGER) AS TEXT) = digits
|
|
52
|
+
AND prefix GLOB '*:pr:' AND length(prefix) > 4
|
|
53
|
+
) p
|
|
54
|
+
JOIN pr_snapshot s ON lower(s.repo) = p.repo AND s.number = p.number,
|
|
55
|
+
json_each(
|
|
56
|
+
CASE WHEN json_valid(p.value) THEN
|
|
57
|
+
CASE WHEN json_type(p.value, '$.ticketKeys') = 'array' THEN p.value END
|
|
58
|
+
END,
|
|
59
|
+
'$.ticketKeys'
|
|
60
|
+
) k
|
|
61
|
+
WHERE k.type = 'text';
|
|
62
|
+
|
|
63
|
+
DROP INDEX pr_snapshot_lower_identity;
|