@omercnet/paseo-pr-radar 3.3.0-next.529.1 → 3.3.0-next.530.1
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/package.json +1 -1
- package/server/viewer-scope.ts +65 -13
package/package.json
CHANGED
package/server/viewer-scope.ts
CHANGED
|
@@ -200,16 +200,21 @@ async function searchIssues(
|
|
|
200
200
|
"--order=desc",
|
|
201
201
|
`--json=${fields}`,
|
|
202
202
|
]);
|
|
203
|
-
const parsed = JSON.parse(output);
|
|
204
|
-
return {
|
|
205
|
-
|
|
206
|
-
failed: false,
|
|
207
|
-
};
|
|
203
|
+
const parsed: unknown = JSON.parse(output);
|
|
204
|
+
if (!Array.isArray(parsed)) return { records: [], failed: true };
|
|
205
|
+
return { records: parsed as IssueSearchRecord[], failed: false };
|
|
208
206
|
} catch {
|
|
209
207
|
return { records: [], failed: true };
|
|
210
208
|
}
|
|
211
209
|
}
|
|
212
210
|
|
|
211
|
+
/** When one issue matches several searches it is shown under the highest-ranked role. */
|
|
212
|
+
const ISSUE_ROLE_RANK: Record<GitHubIssueItem["role"], number> = {
|
|
213
|
+
owner: 0,
|
|
214
|
+
assignee: 1,
|
|
215
|
+
author: 2,
|
|
216
|
+
};
|
|
217
|
+
|
|
213
218
|
function toIssueItem(record: IssueSearchRecord, role: GitHubIssueItem["role"]): GitHubIssueItem {
|
|
214
219
|
const labels = record.labels.map(({ name }) => name);
|
|
215
220
|
const authorKind =
|
|
@@ -476,12 +481,23 @@ interface Snapshot {
|
|
|
476
481
|
issueItems: GitHubIssueItem[];
|
|
477
482
|
issueTruncated: boolean;
|
|
478
483
|
issueSearchFailures: number;
|
|
484
|
+
/** When each role's issue search last succeeded (ms); a role's kept issues age from here. */
|
|
485
|
+
issueFreshAt: Record<GitHubIssueItem["role"], number>;
|
|
486
|
+
/** Whether each role's list hit the search cap; a kept role keeps its flag. */
|
|
487
|
+
issueTruncatedBy: Record<GitHubIssueItem["role"], boolean>;
|
|
479
488
|
enrichmentFailures: number;
|
|
480
489
|
acknowledgedAt: string | null;
|
|
481
490
|
}
|
|
482
491
|
|
|
483
|
-
/**
|
|
484
|
-
|
|
492
|
+
/**
|
|
493
|
+
* The expensive part: ~5 s of gh searches and GraphQL enrichment. `previous` is the window's last
|
|
494
|
+
* snapshot: a failed issue search keeps its role's share of the issues it held, since an empty
|
|
495
|
+
* answer from a failed call says nothing about the issues. Only for the same viewer, and only
|
|
496
|
+
* while that role's last good search is within MAX_STALE_MS, so failures cannot hide behind old
|
|
497
|
+
* data forever (the coverage note keeps reporting them). A snapshot holding kept issues can still
|
|
498
|
+
* be served for up to MAX_STALE_MS more if the refreshes after it throw outright.
|
|
499
|
+
*/
|
|
500
|
+
async function fetchSnapshot(windowDays: number, previous?: Snapshot): Promise<Snapshot> {
|
|
485
501
|
const viewer = await viewerLogin();
|
|
486
502
|
const since = new Date(Date.now() - windowDays * 24 * 60 * 60 * 1_000).toISOString().slice(0, 10);
|
|
487
503
|
const [
|
|
@@ -507,10 +523,38 @@ async function fetchSnapshot(windowDays: number): Promise<Snapshot> {
|
|
|
507
523
|
issueMap.set(record.id, toIssueItem(record, "assignee"));
|
|
508
524
|
for (const record of authoredIssues.records)
|
|
509
525
|
issueMap.set(record.id, toIssueItem(record, "author"));
|
|
510
|
-
const
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
526
|
+
const searchedAt = Date.now();
|
|
527
|
+
const kept = previous?.viewer === viewer ? previous : undefined;
|
|
528
|
+
const searches = [
|
|
529
|
+
["author", authoredIssues],
|
|
530
|
+
["assignee", assignedIssues],
|
|
531
|
+
["owner", ownedIssues],
|
|
532
|
+
] as const;
|
|
533
|
+
const issueFreshAt = { author: 0, assignee: 0, owner: 0 };
|
|
534
|
+
const issueTruncatedBy = { author: false, assignee: false, owner: false };
|
|
535
|
+
const keptRoles = new Set<GitHubIssueItem["role"]>();
|
|
536
|
+
for (const [role, result] of searches) {
|
|
537
|
+
if (!result.failed) {
|
|
538
|
+
issueFreshAt[role] = searchedAt;
|
|
539
|
+
issueTruncatedBy[role] = result.records.length === SEARCH_LIMIT;
|
|
540
|
+
} else if (kept) {
|
|
541
|
+
issueFreshAt[role] = kept.issueFreshAt[role];
|
|
542
|
+
if (searchedAt - issueFreshAt[role] <= MAX_STALE_MS) {
|
|
543
|
+
keptRoles.add(role);
|
|
544
|
+
issueTruncatedBy[role] = kept.issueTruncatedBy[role];
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
for (const item of kept?.issueItems ?? []) {
|
|
549
|
+
if (!keptRoles.has(item.role)) continue;
|
|
550
|
+
const fresh = issueMap.get(item.id);
|
|
551
|
+
if (!fresh) issueMap.set(item.id, item);
|
|
552
|
+
// Fresh fields win, but the kept row remembers a higher-ranked role whose search failed.
|
|
553
|
+
else if (ISSUE_ROLE_RANK[item.role] > ISSUE_ROLE_RANK[fresh.role]) {
|
|
554
|
+
issueMap.set(item.id, { ...fresh, role: item.role });
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
const issueTruncated = Object.values(issueTruncatedBy).some(Boolean);
|
|
514
558
|
const issueSearchFailures = [authoredIssues, assignedIssues, ownedIssues].filter(
|
|
515
559
|
(res) => res.failed,
|
|
516
560
|
).length;
|
|
@@ -576,6 +620,8 @@ async function fetchSnapshot(windowDays: number): Promise<Snapshot> {
|
|
|
576
620
|
issueItems,
|
|
577
621
|
issueTruncated,
|
|
578
622
|
issueSearchFailures,
|
|
623
|
+
issueFreshAt,
|
|
624
|
+
issueTruncatedBy,
|
|
579
625
|
enrichmentFailures: enrichment.failures,
|
|
580
626
|
acknowledgedAt,
|
|
581
627
|
};
|
|
@@ -598,7 +644,7 @@ export function projectSnapshot(snapshot: Snapshot, urls: string[]): ViewerScope
|
|
|
598
644
|
}
|
|
599
645
|
if (snapshot.issueSearchFailures > 0) {
|
|
600
646
|
notes.push(
|
|
601
|
-
`${snapshot.issueSearchFailures} GitHub issue search request${snapshot.issueSearchFailures === 1 ? "" : "s"} failed; issue list may be incomplete.`,
|
|
647
|
+
`${snapshot.issueSearchFailures} GitHub issue search request${snapshot.issueSearchFailures === 1 ? "" : "s"} failed; issue list may be stale or incomplete.`,
|
|
602
648
|
);
|
|
603
649
|
}
|
|
604
650
|
const coverageNote =
|
|
@@ -663,7 +709,7 @@ function refreshWindow(windowDays: number): Promise<Snapshot> {
|
|
|
663
709
|
const running = inflight.get(windowDays);
|
|
664
710
|
if (running) return running;
|
|
665
711
|
const started = Date.now();
|
|
666
|
-
const promise = fetchSnapshot(windowDays)
|
|
712
|
+
const promise = fetchSnapshot(windowDays, snapshots.get(windowDays)?.snapshot)
|
|
667
713
|
.then((snapshot) => {
|
|
668
714
|
snapshots.set(windowDays, { snapshot, at: Date.now() });
|
|
669
715
|
console.log(
|
|
@@ -720,6 +766,12 @@ export async function resolveViewerScope({
|
|
|
720
766
|
}
|
|
721
767
|
}
|
|
722
768
|
|
|
769
|
+
/** Test seam: waits for running refreshes to finish, keeping the cache. */
|
|
770
|
+
export async function settleViewerScopeRefreshes(): Promise<void> {
|
|
771
|
+
await Promise.allSettled([...inflight.values()]);
|
|
772
|
+
await stateQueue;
|
|
773
|
+
}
|
|
774
|
+
|
|
723
775
|
/** Test seam: waits for running refreshes so tests do not bleed into each other. */
|
|
724
776
|
export async function resetViewerScopeCache(): Promise<void> {
|
|
725
777
|
await Promise.allSettled([...inflight.values()]);
|