Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion extensions/github1s/src/adapters/github1s/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
10 changes: 3 additions & 7 deletions extensions/github1s/src/adapters/github1s/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -56,7 +55,6 @@ export class GitHubFetcher {
private _request: Octokit['request'] | null = null;
public onDidChangePreferSourcegraphApi = this._emitter.event;
private _currentRepoPromise: Promise<any> | null = null;
private _sgApiTimeout: boolean = false;

public request: Octokit['request'];
public graphql: Octokit['graphql'];
Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -136,7 +132,7 @@ export class GitHubFetcher {
const targetRepo = repo || (await getCurrentRepo());
const globalState = getExtensionContext().globalState;
const cachedData: Record<string, boolean> | 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) {
Expand Down
6 changes: 3 additions & 3 deletions workers/discovery/src/snapshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<KVNamespace, 'put'>,
Expand All @@ -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 });
Expand Down
Loading