Skip to content

Commit

Permalink
Improve cache manipulation
Browse files Browse the repository at this point in the history
  • Loading branch information
lszomoru committed Nov 16, 2023
1 parent f7f893c commit d2c47c8
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/vs/workbench/contrib/scm/browser/scmViewPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3103,7 +3103,7 @@ class SCMTreeDataSource implements IAsyncDataSource<ISCMViewService, TreeElement
}

const children: SCMHistoryItemGroupTreeElement[] = [];
const historyProviderCacheEntry = this.historyProviderCache.get(element)!;
const historyProviderCacheEntry = this.getHistoryProviderCacheEntry(element);
let historyItemGroupDetails = historyProviderCacheEntry?.historyItemGroupDetails;

if (!historyItemGroupDetails) {
Expand Down Expand Up @@ -3147,7 +3147,7 @@ class SCMTreeDataSource implements IAsyncDataSource<ISCMViewService, TreeElement
return [];
}

const historyProviderCacheEntry = this.historyProviderCache.get(repository)!;
const historyProviderCacheEntry = this.getHistoryProviderCacheEntry(repository);
const historyItemsMap = historyProviderCacheEntry.historyItems;
let historyItems = historyProviderCacheEntry.historyItems.get(element.id);

Expand All @@ -3174,7 +3174,7 @@ class SCMTreeDataSource implements IAsyncDataSource<ISCMViewService, TreeElement
return [];
}

const historyProviderCacheEntry = this.historyProviderCache.get(repository)!;
const historyProviderCacheEntry = this.getHistoryProviderCacheEntry(repository);
const historyItemChangesMap = historyProviderCacheEntry.historyItemChanges;
let historyItemChanges = historyItemChangesMap.get(element.id);

Expand Down Expand Up @@ -3249,11 +3249,6 @@ class SCMTreeDataSource implements IAsyncDataSource<ISCMViewService, TreeElement
for (const repository of added) {
const repositoryDisposables = new DisposableStore();

this.historyProviderCache.set(repository, {
historyItems: new Map<string, ISCMHistoryItem[]>(),
historyItemChanges: new Map<string, ISCMHistoryItemChange[]>()
});

if (repository.provider.historyProvider) {
repositoryDisposables.add(repository.provider.historyProvider.onDidChangeCurrentHistoryItemGroup(() => this.historyProviderCache.delete(repository)));
}
Expand All @@ -3268,6 +3263,14 @@ class SCMTreeDataSource implements IAsyncDataSource<ISCMViewService, TreeElement
}
}

private getHistoryProviderCacheEntry(repository: ISCMRepository): ISCMHistoryProviderCacheEntry {
return this.historyProviderCache.get(repository) ?? {
historyItemGroupDetails: undefined,
historyItems: new Map<string, ISCMHistoryItem[]>(),
historyItemChanges: new Map<string, ISCMHistoryItemChange[]>()
};
}

dispose(): void {
this.repositoryDisposables.dispose();
this.disposables.dispose();
Expand Down

0 comments on commit d2c47c8

Please sign in to comment.