Skip to content

Commit

Permalink
fix scm history going out of sync after commit (with fixed avatar cac…
Browse files Browse the repository at this point in the history
…he) (#12837)

* fix scm history going out of sync after commit and cache commit avatars

Signed-off-by: Carey Williams <[email protected]>
Co-authored-by: Erez Odier <[email protected]>
  • Loading branch information
CareyJWilliams and erezmus authored Aug 21, 2023
1 parent 20e3771 commit c483ccb
Showing 1 changed file with 14 additions and 11 deletions.
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

0 comments on commit c483ccb

Please sign in to comment.