diff --git a/extensions/copilot/src/platform/workspaceChunkSearch/node/codeSearch/codeSearchChunkSearch.ts b/extensions/copilot/src/platform/workspaceChunkSearch/node/codeSearch/codeSearchChunkSearch.ts index 580f9356695..e42af39df46 100644 --- a/extensions/copilot/src/platform/workspaceChunkSearch/node/codeSearch/codeSearchChunkSearch.ts +++ b/extensions/copilot/src/platform/workspaceChunkSearch/node/codeSearch/codeSearchChunkSearch.ts @@ -8,7 +8,7 @@ import { shouldInclude } from '../../../../util/common/glob'; import { Result } from '../../../../util/common/result'; import { CallTracker, TelemetryCorrelationId } from '../../../../util/common/telemetryCorrelationId'; import { coalesce } from '../../../../util/vs/base/common/arrays'; -import { IntervalTimer, raceCancellationError, raceTimeout } from '../../../../util/vs/base/common/async'; +import { raceCancellationError, raceTimeout } from '../../../../util/vs/base/common/async'; import { CancellationToken, CancellationTokenSource } from '../../../../util/vs/base/common/cancellation'; import { isCancellationError } from '../../../../util/vs/base/common/errors'; import { Emitter, Event } from '../../../../util/vs/base/common/event'; @@ -183,19 +183,14 @@ export class CodeSearchChunkSearch extends Disposable implements IWorkspaceChunk this.closeRepo(info.repo); })); - const refreshInterval = this._register(new IntervalTimer()); - refreshInterval.cancelAndSet(() => this.updateIndexedCommitForAllRepos(), 5 * 60 * 1000); // 5 minutes - // When the authentication state changes, update repos - this._register(Event.any( - this._authenticationService.onDidAuthenticationChange, - this._adoCodeSearchService.onDidChangeIndexState - )(() => { + this._register(this._authenticationService.onDidAuthenticationChange(() => { this.updateRepoStatuses(); })); this._register(Event.any( - this._authenticationService.onDidAdoAuthenticationChange + this._authenticationService.onDidAdoAuthenticationChange, + this._adoCodeSearchService.onDidChangeIndexState )(() => { this.updateRepoStatuses('ado'); })); @@ -996,16 +991,6 @@ export class CodeSearchChunkSearch extends Disposable implements IWorkspaceChunk return undefined; } - private updateIndexedCommitForAllRepos(): void { - this._logService.trace(`CodeSearchChunkSearch.updateIndexedCommitForAllRepos`); - - for (const entry of this._codeSearchRepos.values()) { - if (entry.repo.status === CodeSearchRepoStatus.Ready) { - entry.repo.refreshStatusFromEndpoint(true, CancellationToken.None); - } - } - } - public deleteExternalIngestWorkspaceIndex(callTracker: CallTracker, token: CancellationToken): Promise { return this._externalIngestIndex.value.deleteIndex(callTracker, token); } diff --git a/extensions/copilot/src/platform/workspaceChunkSearch/node/codeSearch/codeSearchRepo.ts b/extensions/copilot/src/platform/workspaceChunkSearch/node/codeSearch/codeSearchRepo.ts index b0f07e7b8be..c89b09003ce 100644 --- a/extensions/copilot/src/platform/workspaceChunkSearch/node/codeSearch/codeSearchRepo.ts +++ b/extensions/copilot/src/platform/workspaceChunkSearch/node/codeSearch/codeSearchRepo.ts @@ -263,7 +263,7 @@ abstract class BaseRemoteCodeSearchRepo extends Disposable implements CodeSearch return newState; } - private async fetchRemoteIndexState(token: CancellationToken): Promise { + protected async fetchRemoteIndexState(token: CancellationToken): Promise { this._logService.trace(`CodeSearchChunkSearch.getRepoIndexStatusFromEndpoint(${this.repoInfo.rootUri}`); const statusResult = await this.doFetchRemoteIndexState(token); @@ -418,12 +418,21 @@ export class GithubCodeSearchRepo extends BaseRemoteCodeSearchRepo { const startRepoStatus = this.status; await measureExecTime(() => raceTimeout((async () => { + if (this.status === CodeSearchRepoStatus.Ready) { + // Try to update the indexed commit to ensure we're up to date + const newState = await raceCancellationError(this.fetchRemoteIndexState(token), token); + this.updateState(newState); + return; + } + // Trigger indexing if we have not already - if (startRepoStatus === CodeSearchRepoStatus.NotYetIndexed) { + if (this.status === CodeSearchRepoStatus.NotYetIndexed) { const triggerResult = await raceCancellationError(this.triggerRemoteIndexingOfRepo('auto', telemetryInfo), token); if (triggerResult.isError()) { throw new Error(`CodeSearchChunkSearch: Triggering indexing of '${this.remoteInfo.repoId}' failed: ${triggerResult.err.id}`); } + + // Continue } if (this.status === CodeSearchRepoStatus.BuildingIndex) {