Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix scm history going out of sync after commit (with fixed avatar cache) #12837

Merged
merged 2 commits into from
Aug 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions packages/scm-extra/src/browser/history/scm-history-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ export class ScmHistoryWidget extends ScmNavigableListWidget<ScmHistoryListNode>
}

protected async addCommits(options?: HistoryWidgetOptions): Promise<void> {
// const repository: Repository | undefined = this.repositoryProvider.findRepositoryOrSelected(options);
const repository = this.scmService.selectedRepository;

this.cancelIndicator.cancel();
Expand All @@ -189,19 +188,17 @@ export class ScmHistoryWidget extends ScmNavigableListWidget<ScmHistoryListNode>
if (repository) {
if (this.historySupport) {
try {
const currentCommits = this.status.state === 'ready' ? this.status.commits : [];

let history = await this.historySupport.getCommitHistory(options);
const history = await this.historySupport.getCommitHistory(options);
if (token.isCancellationRequested || !this.hasMoreCommits) {
return;
}

if (options && ((options.maxCount && history.length < options.maxCount) || (!options.maxCount && currentCommits))) {
if (options && (options.maxCount && history.length < options.maxCount)) {
this.hasMoreCommits = false;
}
if (currentCommits.length > 0) {
history = history.slice(1);
}

const avatarCache = new Map<string, string>();

const commits: ScmCommitNode[] = [];
for (const commit of history) {
const fileChangeNodes: ScmFileChangeNode[] = [];
Expand All @@ -211,7 +208,14 @@ export class ScmHistoryWidget extends ScmNavigableListWidget<ScmHistoryListNode>
});
}));

const avatarUrl = await this.avatarService.getAvatar(commit.authorEmail);
let avatarUrl = '';
if (avatarCache.has(commit.authorEmail)) {
avatarUrl = avatarCache.get(commit.authorEmail)!;
} else {
avatarUrl = await this.avatarService.getAvatar(commit.authorEmail);
avatarCache.set(commit.authorEmail, avatarUrl);
}

commits.push({
commitDetails: commit,
authorAvatar: avatarUrl,
Expand All @@ -220,8 +224,7 @@ export class ScmHistoryWidget extends ScmNavigableListWidget<ScmHistoryListNode>
selected: false
});
}
currentCommits.push(...commits);
this.status = { state: 'ready', commits: currentCommits };
this.status = { state: 'ready', commits };
} catch (error) {
if (options && options.uri && repository) {
this.hasMoreCommits = false;
Expand Down
Loading