Skip to content

Commit

Permalink
Introduce session ids for caching (#229064)
Browse files Browse the repository at this point in the history
* introduce session ids for caching

* fix formatting
  • Loading branch information
benibenj committed Sep 19, 2024
1 parent a7f27dc commit a7902a2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/vs/base/browser/ui/tree/asyncDataTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class AsyncDataTreeNodeListDragAndDrop<TInput, T> implements IListDragAndDrop<IA
}

export interface IAsyncFindProvider<T> {
getFindResults(pattern: string, token: CancellationToken): AsyncIterable<T>;
getFindResults(pattern: string, sessionId: number, token: CancellationToken): AsyncIterable<T>;
revealResultInTree?(findElement: T): void;
}

Expand Down Expand Up @@ -382,6 +382,7 @@ class AsyncFindController<TInput, T, TFilterData> extends AbstractFindController

protected toggles = [];

private sessionId: number = 0;
private active: boolean = false;

private activeTokenSource: CancellationTokenSource | undefined;
Expand Down Expand Up @@ -421,6 +422,7 @@ class AsyncFindController<TInput, T, TFilterData> extends AbstractFindController
}

private activateFindMode(): void {
this.sessionId++;
this.previousTreeScrollTop = this.tree.scrollTop;
this.tree.scrollTop = 0;
const findModel = this.tree.createNewModel({ filter: this.filter as ITreeFilter<IAsyncDataTreeNode<TInput, T> | null, TFilterData> });
Expand Down Expand Up @@ -454,7 +456,7 @@ class AsyncFindController<TInput, T, TFilterData> extends AbstractFindController

this.activeTokenSource = new CancellationTokenSource();

const results = this.findProvider.getFindResults(pattern, this.activeTokenSource.token);
const results = this.findProvider.getFindResults(pattern, this.sessionId, this.activeTokenSource.token);
this.pocessFindResults(results, this.activeTokenSource.token).then(() => {
if (this.activeTokenSource && !this.activeTokenSource.token.isCancellationRequested) {
this.render();
Expand Down
5 changes: 3 additions & 2 deletions src/vs/workbench/contrib/files/browser/views/explorerView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class ExplorerFindProvider implements IAsyncFindProvider<ExplorerItem> {
@IExplorerService private readonly explorerService: IExplorerService,
) { }

async *getFindResults(pattern: string, token: CancellationToken): AsyncIterable<ExplorerItem> {
async *getFindResults(pattern: string, sessionId: number, token: CancellationToken): AsyncIterable<ExplorerItem> {
const workspaceFolders = this.workspaceContextService.getWorkspace().folders;
const folderPromises = Promise.all(workspaceFolders.map(async folder => {
// Get exclude settings used for search
Expand All @@ -178,6 +178,7 @@ class ExplorerFindProvider implements IAsyncFindProvider<ExplorerItem> {
filePattern: pattern,
maxResults: 100,
sortByScore: true,
cacheKey: `explorerfindprovider:${sessionId}`,
excludePattern: excludePatterns,
}, token);

Expand All @@ -186,7 +187,7 @@ class ExplorerFindProvider implements IAsyncFindProvider<ExplorerItem> {

const folderResults = await this.progressService.withProgress({
location: ProgressLocation.Explorer,
delay: 100,
delay: 1000,
}, _progress => folderPromises);

if (token.isCancellationRequested) {
Expand Down

0 comments on commit a7902a2

Please sign in to comment.