Skip to content

Commit cacd71f

Browse files
authored
SCM - refactor history provider cache cleanup (#198378)
* Initial implementation * Remove private property as it is not needed any more * Improve cache manipulation
1 parent ab66bab commit cacd71f

File tree

1 file changed

+40
-18
lines changed

1 file changed

+40
-18
lines changed

src/vs/workbench/contrib/scm/browser/scmViewPane.ts

+40-18
Original file line numberDiff line numberDiff line change
@@ -2294,7 +2294,6 @@ export class SCMViewPane extends ViewPane {
22942294
private treeScrollTop: number | undefined;
22952295
private treeContainer!: HTMLElement;
22962296
private tree!: WorkbenchCompressibleAsyncDataTree<ISCMViewService, TreeElement, FuzzyScore>;
2297-
private treeDataSource!: SCMTreeDataSource;
22982297

22992298
private listLabels!: ResourceLabels;
23002299
private inputRenderer!: InputRenderer;
@@ -2529,7 +2528,8 @@ export class SCMViewPane extends ViewPane {
25292528
actionRunner.onWillRun(() => this.tree.domFocus(), this, this.disposables);
25302529
this.disposables.add(actionRunner);
25312530

2532-
this.treeDataSource = this.instantiationService.createInstance(SCMTreeDataSource, () => this.viewMode, () => this.alwaysShowRepositories, () => this.showActionButton, () => this.showIncomingChanges, () => this.showOutgoingChanges);
2531+
const treeDataSource = this.instantiationService.createInstance(SCMTreeDataSource, () => this.viewMode, () => this.alwaysShowRepositories, () => this.showActionButton, () => this.showIncomingChanges, () => this.showOutgoingChanges);
2532+
this.disposables.add(treeDataSource);
25332533

25342534
this.tree = this.instantiationService.createInstance(
25352535
WorkbenchCompressibleAsyncDataTree,
@@ -2548,7 +2548,7 @@ export class SCMViewPane extends ViewPane {
25482548
this.instantiationService.createInstance(HistoryItemChangeRenderer, () => this.viewMode, this.listLabels),
25492549
this.instantiationService.createInstance(SeparatorRenderer)
25502550
],
2551-
this.treeDataSource,
2551+
treeDataSource,
25522552
{
25532553
horizontalScrolling: false,
25542554
setRowLineHeight: false,
@@ -2717,10 +2717,7 @@ export class SCMViewPane extends ViewPane {
27172717
}));
27182718

27192719
if (repository.provider.historyProvider) {
2720-
repositoryDisposables.add(repository.provider.historyProvider.onDidChangeCurrentHistoryItemGroup(() => {
2721-
this.treeDataSource.deleteCacheEntry(repository);
2722-
this.updateChildren(repository);
2723-
}));
2720+
repositoryDisposables.add(repository.provider.historyProvider.onDidChangeCurrentHistoryItemGroup(() => this.updateChildren(repository)));
27242721
}
27252722

27262723
const resourceGroupDisposables = repositoryDisposables.add(new DisposableMap<ISCMResourceGroup, IDisposable>());
@@ -2754,7 +2751,6 @@ export class SCMViewPane extends ViewPane {
27542751

27552752
// Removed repositories
27562753
for (const repository of removed) {
2757-
this.treeDataSource.deleteCacheEntry(repository);
27582754
this.items.deleteAndDispose(repository);
27592755
}
27602756

@@ -2973,6 +2969,8 @@ export class SCMViewPane extends ViewPane {
29732969
class SCMTreeDataSource implements IAsyncDataSource<ISCMViewService, TreeElement> {
29742970

29752971
private readonly historyProviderCache = new Map<ISCMRepository, ISCMHistoryProviderCacheEntry>();
2972+
private readonly repositoryDisposables = new DisposableMap<ISCMRepository, IDisposable>();
2973+
private readonly disposables = new DisposableStore();
29762974

29772975
constructor(
29782976
private readonly viewMode: () => ViewMode,
@@ -2982,7 +2980,10 @@ class SCMTreeDataSource implements IAsyncDataSource<ISCMViewService, TreeElement
29822980
private readonly showOutgoingChanges: () => ShowChangesSetting,
29832981
@ISCMViewService private readonly scmViewService: ISCMViewService,
29842982
@IUriIdentityService private uriIdentityService: IUriIdentityService,
2985-
) { }
2983+
) {
2984+
this.scmViewService.onDidChangeVisibleRepositories(this.onDidChangeVisibleRepositories, this, this.disposables);
2985+
this.onDidChangeVisibleRepositories({ added: this.scmViewService.visibleRepositories, removed: Iterable.empty() });
2986+
}
29862987

29872988
hasChildren(inputOrElement: ISCMViewService | TreeElement): boolean {
29882989
if (isSCMViewService(inputOrElement)) {
@@ -3212,13 +3213,6 @@ class SCMTreeDataSource implements IAsyncDataSource<ISCMViewService, TreeElement
32123213
return children;
32133214
}
32143215

3215-
private getHistoryProviderCacheEntry(repository: ISCMRepository): ISCMHistoryProviderCacheEntry {
3216-
return this.historyProviderCache.get(repository) ?? {
3217-
historyItems: new Map<string, ISCMHistoryItem[]>(),
3218-
historyItemChanges: new Map<string, ISCMHistoryItemChange[]>()
3219-
};
3220-
}
3221-
32223216
getParent(element: TreeElement): ISCMViewService | TreeElement {
32233217
if (isSCMResourceNode(element)) {
32243218
if (element.parent === element.context.resourceTree.root) {
@@ -3250,8 +3244,36 @@ class SCMTreeDataSource implements IAsyncDataSource<ISCMViewService, TreeElement
32503244
}
32513245
}
32523246

3253-
deleteCacheEntry(repository: ISCMRepository): void {
3254-
this.historyProviderCache.delete(repository);
3247+
private onDidChangeVisibleRepositories({ added, removed }: ISCMViewVisibleRepositoryChangeEvent): void {
3248+
// Added repositories
3249+
for (const repository of added) {
3250+
const repositoryDisposables = new DisposableStore();
3251+
3252+
if (repository.provider.historyProvider) {
3253+
repositoryDisposables.add(repository.provider.historyProvider.onDidChangeCurrentHistoryItemGroup(() => this.historyProviderCache.delete(repository)));
3254+
}
3255+
3256+
this.repositoryDisposables.set(repository, repositoryDisposables);
3257+
}
3258+
3259+
// Removed repositories
3260+
for (const repository of removed) {
3261+
this.repositoryDisposables.deleteAndDispose(repository);
3262+
this.historyProviderCache.delete(repository);
3263+
}
3264+
}
3265+
3266+
private getHistoryProviderCacheEntry(repository: ISCMRepository): ISCMHistoryProviderCacheEntry {
3267+
return this.historyProviderCache.get(repository) ?? {
3268+
historyItemGroupDetails: undefined,
3269+
historyItems: new Map<string, ISCMHistoryItem[]>(),
3270+
historyItemChanges: new Map<string, ISCMHistoryItemChange[]>()
3271+
};
3272+
}
3273+
3274+
dispose(): void {
3275+
this.repositoryDisposables.dispose();
3276+
this.disposables.dispose();
32553277
}
32563278
}
32573279

0 commit comments

Comments
 (0)