Skip to content

Commit c483ccb

Browse files
fix scm history going out of sync after commit (with fixed avatar cache) (#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]>
1 parent 20e3771 commit c483ccb

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

packages/scm-extra/src/browser/history/scm-history-widget.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ export class ScmHistoryWidget extends ScmNavigableListWidget<ScmHistoryListNode>
179179
}
180180

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

185184
this.cancelIndicator.cancel();
@@ -189,19 +188,17 @@ export class ScmHistoryWidget extends ScmNavigableListWidget<ScmHistoryListNode>
189188
if (repository) {
190189
if (this.historySupport) {
191190
try {
192-
const currentCommits = this.status.state === 'ready' ? this.status.commits : [];
193-
194-
let history = await this.historySupport.getCommitHistory(options);
191+
const history = await this.historySupport.getCommitHistory(options);
195192
if (token.isCancellationRequested || !this.hasMoreCommits) {
196193
return;
197194
}
198195

199-
if (options && ((options.maxCount && history.length < options.maxCount) || (!options.maxCount && currentCommits))) {
196+
if (options && (options.maxCount && history.length < options.maxCount)) {
200197
this.hasMoreCommits = false;
201198
}
202-
if (currentCommits.length > 0) {
203-
history = history.slice(1);
204-
}
199+
200+
const avatarCache = new Map<string, string>();
201+
205202
const commits: ScmCommitNode[] = [];
206203
for (const commit of history) {
207204
const fileChangeNodes: ScmFileChangeNode[] = [];
@@ -211,7 +208,14 @@ export class ScmHistoryWidget extends ScmNavigableListWidget<ScmHistoryListNode>
211208
});
212209
}));
213210

214-
const avatarUrl = await this.avatarService.getAvatar(commit.authorEmail);
211+
let avatarUrl = '';
212+
if (avatarCache.has(commit.authorEmail)) {
213+
avatarUrl = avatarCache.get(commit.authorEmail)!;
214+
} else {
215+
avatarUrl = await this.avatarService.getAvatar(commit.authorEmail);
216+
avatarCache.set(commit.authorEmail, avatarUrl);
217+
}
218+
215219
commits.push({
216220
commitDetails: commit,
217221
authorAvatar: avatarUrl,
@@ -220,8 +224,7 @@ export class ScmHistoryWidget extends ScmNavigableListWidget<ScmHistoryListNode>
220224
selected: false
221225
});
222226
}
223-
currentCommits.push(...commits);
224-
this.status = { state: 'ready', commits: currentCommits };
227+
this.status = { state: 'ready', commits };
225228
} catch (error) {
226229
if (options && options.uri && repository) {
227230
this.hasMoreCommits = false;

0 commit comments

Comments
 (0)