ソースを参照

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;

読み込み中…
キャンセル
保存