Sfoglia il codice sorgente

Optimizes gravatar lookup, since this is perf sensative code

main
Eric Amodio 6 anni fa
parent
commit
079b6f4b6e
1 ha cambiato i file con 8 aggiunte e 6 eliminazioni
  1. +8
    -6
      src/git/models/commit.ts

+ 8
- 6
src/git/models/commit.ts Vedi File

@ -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;

Caricamento…
Annulla
Salva