fix: preserve fallback PR cache on refresh miss (#2566)
This commit is contained in:
@@ -156,6 +156,19 @@ function freshRetryAt(candidate: GitHubPRRefreshCandidate): number | null {
|
||||
: candidate.cachedFetchedAt + refreshIntervalForCandidate(candidate)
|
||||
}
|
||||
|
||||
function aliasFromCandidate(candidate: GitHubPRRefreshCandidate): GitHubPRRefreshAlias {
|
||||
return {
|
||||
cacheKey: candidate.cacheKey,
|
||||
repoId: candidate.repoId,
|
||||
repoPath: candidate.repoPath,
|
||||
branch: candidate.branch,
|
||||
worktreeId: candidate.worktreeId,
|
||||
connectionId: candidate.connectionId ?? null,
|
||||
linkedPRNumber: candidate.linkedPRNumber ?? null,
|
||||
fallbackPRNumber: candidate.linkedPRNumber == null ? (candidate.fallbackPRNumber ?? null) : null
|
||||
}
|
||||
}
|
||||
|
||||
function visibleCandidateAfterOutcome(
|
||||
candidate: GitHubPRRefreshCandidate,
|
||||
outcome: PRRefreshOutcome
|
||||
@@ -457,14 +470,7 @@ export function enqueuePRRefresh(
|
||||
priority = 0,
|
||||
windowId?: number
|
||||
): void {
|
||||
const alias: GitHubPRRefreshAlias = {
|
||||
cacheKey: candidate.cacheKey,
|
||||
repoId: candidate.repoId,
|
||||
repoPath: candidate.repoPath,
|
||||
branch: candidate.branch,
|
||||
worktreeId: candidate.worktreeId,
|
||||
connectionId: candidate.connectionId ?? null
|
||||
}
|
||||
const alias = aliasFromCandidate(candidate)
|
||||
const key = refreshKey(candidate)
|
||||
const skippedReason = validateCandidate(candidate)
|
||||
if (skippedReason) {
|
||||
@@ -541,20 +547,12 @@ export function reportVisiblePRRefreshCandidates(
|
||||
}
|
||||
|
||||
export async function refreshPRNow(candidate: GitHubPRRefreshCandidate): Promise<PRRefreshOutcome> {
|
||||
const alias: GitHubPRRefreshAlias = {
|
||||
cacheKey: candidate.cacheKey,
|
||||
repoId: candidate.repoId,
|
||||
repoPath: candidate.repoPath,
|
||||
branch: candidate.branch,
|
||||
worktreeId: candidate.worktreeId,
|
||||
connectionId: candidate.connectionId ?? null
|
||||
}
|
||||
const alias = aliasFromCandidate(candidate)
|
||||
const key = refreshKey(candidate)
|
||||
const existing = queue.get(key)
|
||||
const aliases = existing ? Array.from(existing.aliases.values()) : [alias]
|
||||
if (!aliases.some((entry) => entry.cacheKey === alias.cacheKey)) {
|
||||
aliases.push(alias)
|
||||
}
|
||||
const aliasMap = new Map(existing ? existing.aliases : [])
|
||||
aliasMap.set(alias.cacheKey, alias)
|
||||
const aliases = Array.from(aliasMap.values())
|
||||
const skippedReason = validateCandidate(candidate)
|
||||
if (skippedReason) {
|
||||
removeQueuedAliasForInvalidCandidate(key, alias)
|
||||
|
||||
Reference in New Issue
Block a user