packager: GlobalTransformCache: cache the transform options digest

Reviewed By: davidaurelio

Differential Revision: D4906974

fbshipit-source-id: b6cf83ba6a072400685948329070e171f65c837d
This commit is contained in:
Jean Lauliac 2017-04-19 03:07:03 -07:00 коммит произвёл Facebook Github Bot
Родитель 9dc7654a6c
Коммит de3478c1b1
2 изменённых файлов: 17 добавлений и 3 удалений

Просмотреть файл

@ -225,7 +225,7 @@ class URIBasedGlobalTransformCache {
keyOf(props: FetchProps) { keyOf(props: FetchProps) {
const hash = crypto.createHash('sha1'); const hash = crypto.createHash('sha1');
const {sourceCode, filePath, transformOptions} = props; const {sourceCode, filePath, transformOptions} = props;
this._optionsHasher.hashTransformWorkerOptions(hash, transformOptions); hash.update(this._optionsHasher.getTransformWorkerOptionsDigest(transformOptions));
const cacheKey = props.getTransformCacheKey(sourceCode, filePath, transformOptions); const cacheKey = props.getTransformCacheKey(sourceCode, filePath, transformOptions);
hash.update(JSON.stringify(cacheKey)); hash.update(JSON.stringify(cacheKey));
hash.update(crypto.createHash('sha1').update(sourceCode).digest('hex')); hash.update(crypto.createHash('sha1').update(sourceCode).digest('hex'));
@ -313,9 +313,23 @@ class URIBasedGlobalTransformCache {
class OptionsHasher { class OptionsHasher {
_rootPath: string; _rootPath: string;
_cache: WeakMap<TransformWorkerOptions, string>;
constructor(rootPath: string) { constructor(rootPath: string) {
this._rootPath = rootPath; this._rootPath = rootPath;
this._cache = new WeakMap();
}
getTransformWorkerOptionsDigest(options: TransformWorkerOptions): string {
const digest = this._cache.get(options);
if (digest != null) {
return digest;
}
const hash = crypto.createHash('sha1');
this.hashTransformWorkerOptions(hash, options);
const newDigest = hash.digest('hex');
this._cache.set(options, newDigest);
return newDigest;
} }
/** /**

Просмотреть файл

@ -19,12 +19,12 @@ Object {
exports[`GlobalTransformCache fetches results 1`] = ` exports[`GlobalTransformCache fetches results 1`] = `
Array [ Array [
Object { Object {
"code": "/* code from http://globalcache.com/fb94b11256237327e4eef5daa08bad33573b3781-foo.js */", "code": "/* code from http://globalcache.com/43e279be6916de8be463ef98bd72ded391608371-foo.js */",
"dependencies": Array [], "dependencies": Array [],
"dependencyOffsets": Array [], "dependencyOffsets": Array [],
}, },
Object { Object {
"code": "/* code from http://globalcache.com/b902b4a8841fcea2919c2fe9b21e68d96dff59c9-bar.js */", "code": "/* code from http://globalcache.com/e09598ad4c807cb22b32d68cfc16e0cba7fdb85c-bar.js */",
"dependencies": Array [], "dependencies": Array [],
"dependencyOffsets": Array [], "dependencyOffsets": Array [],
}, },