瀏覽代碼

Optimizes gravatar lookup, since this is perf sensative code

main
Eric Amodio 6 年之前
父節點
當前提交
079b6f4b6e
共有 1 個檔案被更改,包括 8 行新增6 行删除
  1. +8
    -6
      src/git/models/commit.ts

+ 8
- 6
src/git/models/commit.ts 查看文件

@ -8,6 +8,8 @@ import { Git } from '../git';
import { GitUri } from '../gitUri';
const gravatarCache: Map<string, Uri> = new Map();
const missingGravatarHash = '00000000000000000000000000000000';
export function clearGravatarCache() {
gravatarCache.clear();
}
@ -178,16 +180,16 @@ export abstract class GitCommit {
}
getGravatarUri(fallback: GravatarDefaultStyle, size: number = 16): Uri {
const key = this.email ? `${this.email.trim().toLowerCase()}:${size}` : '';
const hash =
this.email != null && this.email.length !== 0
? Strings.md5(this.email.trim().toLowerCase(), 'hex')
: missingGravatarHash;
const key = `${hash}:${size}`;
let gravatar = gravatarCache.get(key);
if (gravatar !== undefined) return gravatar;
gravatar = Uri.parse(
`https://www.gravatar.com/avatar/${
this.email ? Strings.md5(this.email.trim().toLowerCase(), 'hex') : '00000000000000000000000000000000'
}.jpg?s=${size}&d=${fallback}`
);
gravatar = Uri.parse(`https://www.gravatar.com/avatar/${hash}.jpg?s=${size}&d=${fallback}`);
gravatarCache.set(key, gravatar);
return gravatar;

Loading…
取消
儲存