Skip to content

Commit

Permalink
SCM - refactor history provider cache cleanup (#198378)
Browse files Browse the repository at this point in the history
* Initial implementation

* Remove private property as it is not needed any more

* Improve cache manipulation
  • Loading branch information
lszomoru authored Nov 16, 2023
1 parent ab66bab commit cacd71f
Showing 1 changed file with 40 additions and 18 deletions.
58 changes: 40 additions & 18 deletions src/vs/workbench/contrib/scm/browser/scmViewPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2294,7 +2294,6 @@ export class SCMViewPane extends ViewPane {
private treeScrollTop: number | undefined;
private treeContainer!: HTMLElement;
private tree!: WorkbenchCompressibleAsyncDataTree<ISCMViewService, TreeElement, FuzzyScore>;
private treeDataSource!: SCMTreeDataSource;

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

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

this.tree = this.instantiationService.createInstance(
WorkbenchCompressibleAsyncDataTree,
Expand All @@ -2548,7 +2548,7 @@ export class SCMViewPane extends ViewPane {
this.instantiationService.createInstance(HistoryItemChangeRenderer, () => this.viewMode, this.listLabels),
this.instantiationService.createInstance(SeparatorRenderer)
],
this.treeDataSource,
treeDataSource,
{
horizontalScrolling: false,
setRowLineHeight: false,
Expand Down Expand Up @@ -2717,10 +2717,7 @@ export class SCMViewPane extends ViewPane {
}));

if (repository.provider.historyProvider) {
repositoryDisposables.add(repository.provider.historyProvider.onDidChangeCurrentHistoryItemGroup(() => {
this.treeDataSource.deleteCacheEntry(repository);
this.updateChildren(repository);
}));
repositoryDisposables.add(repository.provider.historyProvider.onDidChangeCurrentHistoryItemGroup(() => this.updateChildren(repository)));
}

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

// Removed repositories
for (const repository of removed) {
this.treeDataSource.deleteCacheEntry(repository);
this.items.deleteAndDispose(repository);
}

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

private readonly historyProviderCache = new Map<ISCMRepository, ISCMHistoryProviderCacheEntry>();
private readonly repositoryDisposables = new DisposableMap<ISCMRepository, IDisposable>();
private readonly disposables = new DisposableStore();

constructor(
private readonly viewMode: () => ViewMode,
Expand All @@ -2982,7 +2980,10 @@ class SCMTreeDataSource implements IAsyncDataSource<ISCMViewService, TreeElement
private readonly showOutgoingChanges: () => ShowChangesSetting,
@ISCMViewService private readonly scmViewService: ISCMViewService,
@IUriIdentityService private uriIdentityService: IUriIdentityService,
) { }
) {
this.scmViewService.onDidChangeVisibleRepositories(this.onDidChangeVisibleRepositories, this, this.disposables);
this.onDidChangeVisibleRepositories({ added: this.scmViewService.visibleRepositories, removed: Iterable.empty() });
}

hasChildren(inputOrElement: ISCMViewService | TreeElement): boolean {
if (isSCMViewService(inputOrElement)) {
Expand Down Expand Up @@ -3212,13 +3213,6 @@ class SCMTreeDataSource implements IAsyncDataSource<ISCMViewService, TreeElement
return children;
}

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

getParent(element: TreeElement): ISCMViewService | TreeElement {
if (isSCMResourceNode(element)) {
if (element.parent === element.context.resourceTree.root) {
Expand Down Expand Up @@ -3250,8 +3244,36 @@ class SCMTreeDataSource implements IAsyncDataSource<ISCMViewService, TreeElement
}
}

deleteCacheEntry(repository: ISCMRepository): void {
this.historyProviderCache.delete(repository);
private onDidChangeVisibleRepositories({ added, removed }: ISCMViewVisibleRepositoryChangeEvent): void {
// Added repositories
for (const repository of added) {
const repositoryDisposables = new DisposableStore();

if (repository.provider.historyProvider) {
repositoryDisposables.add(repository.provider.historyProvider.onDidChangeCurrentHistoryItemGroup(() => this.historyProviderCache.delete(repository)));
}

this.repositoryDisposables.set(repository, repositoryDisposables);
}

// Removed repositories
for (const repository of removed) {
this.repositoryDisposables.deleteAndDispose(repository);
this.historyProviderCache.delete(repository);
}
}

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 cacd71f

Please sign in to comment.