diff --git a/extensions/github1s/src/adapters/github1s/data-source.ts b/extensions/github1s/src/adapters/github1s/data-source.ts index 0784de551..971befe02 100644 --- a/extensions/github1s/src/adapters/github1s/data-source.ts +++ b/extensions/github1s/src/adapters/github1s/data-source.ts @@ -74,7 +74,9 @@ const trySourcegraphApiFirst = (_target: any, propertyKey: string, descriptor: P if (await githubFetcher.getPreferSourcegraphApi(args[0])) { try { return await sourcegraphDataSource[propertyKey](...args); - } catch (e) {} + } catch { + await githubFetcher.setPreferSourcegraphApi(false, args[0]); + } } return originalMethod.apply(this, args); }; diff --git a/extensions/github1s/src/adapters/github1s/fetcher.ts b/extensions/github1s/src/adapters/github1s/fetcher.ts index 403521fd6..5e0df5bb2 100644 --- a/extensions/github1s/src/adapters/github1s/fetcher.ts +++ b/extensions/github1s/src/adapters/github1s/fetcher.ts @@ -9,7 +9,6 @@ import { getExtensionContext } from '@/helpers/context'; import { Octokit } from '@octokit/core'; import { GitHub1sAuthenticationView } from './authentication'; import { GitHubTokenManager } from './token'; -import { isNil } from '@/helpers/util'; import { getCurrentRepo } from './parse-path'; import { SourcegraphDataSource } from '../sourcegraph/data-source'; @@ -56,7 +55,6 @@ export class GitHubFetcher { private _request: Octokit['request'] | null = null; public onDidChangePreferSourcegraphApi = this._emitter.event; private _currentRepoPromise: Promise | null = null; - private _sgApiTimeout: boolean = false; public request: Octokit['request']; public graphql: Octokit['graphql']; @@ -124,10 +122,8 @@ export class GitHubFetcher { repo?.private && this.setPreferSourcegraphApi(false); }); } - } catch (e) { - if (e.message && e.message.includes('signal is aborted')) { - this._sgApiTimeout = true; - } + } catch { + await this.setPreferSourcegraphApi(false); } } } @@ -136,7 +132,7 @@ export class GitHubFetcher { const targetRepo = repo || (await getCurrentRepo()); const globalState = getExtensionContext().globalState; const cachedData: Record | undefined = globalState.get(PREFER_SOURCEGRAPH_API); - return !isNil(cachedData?.[targetRepo]) ? !!cachedData?.[targetRepo] : this._sgApiTimeout ? false : true; + return cachedData?.[targetRepo] ?? true; } public async setPreferSourcegraphApi(value: boolean, repo?: string) { diff --git a/workers/discovery/src/snapshots.ts b/workers/discovery/src/snapshots.ts index 9966ca5fe..8e57aacbc 100644 --- a/workers/discovery/src/snapshots.ts +++ b/workers/discovery/src/snapshots.ts @@ -4,8 +4,8 @@ export const LATEST_KEY = 'latest'; export const SNAPSHOT_RETENTION_SECONDS = 90 * 24 * 60 * 60; // Use the scheduled UTC date so execution delays cannot change the archive day. -export const getHistoryKey = (scheduledTime: number): string => - `history:${new Date(scheduledTime).toISOString().slice(0, 10)}`; +export const getGitHubHistoryKey = (scheduledTime: number): string => + `github:${new Date(scheduledTime).toISOString().slice(0, 10)}`; export const saveSnapshot = async ( kv: Pick, @@ -15,7 +15,7 @@ export const saveSnapshot = async ( const expiration = Math.floor(Date.parse(snapshot.generated_at) / 1000) + SNAPSHOT_RETENTION_SECONDS; const json = JSON.stringify(snapshot); // Reruns replace the same day. KV uses last-write-wins, not conditional creation. - await kv.put(getHistoryKey(scheduledTime), json, { expiration }); + await kv.put(getGitHubHistoryKey(scheduledTime), json, { expiration }); // Preserve the previous latest snapshot if collection or archival fails. // Latest also expires so a stopped collector cannot retain data past 90 days. await kv.put(LATEST_KEY, json, { expiration });