refactor(aio): move document path computation

Do the path computation before doing the cache look up.
This commit is contained in:
Peter Bacon Darwin 2017-03-04 16:24:09 +00:00 committed by Igor Minar
parent 66cc88c8a8
commit dd50922747

View File

@ -29,14 +29,14 @@ export class DocumentService {
private getDocument(url: string) { private getDocument(url: string) {
this.logger.log('getting document', url); this.logger.log('getting document', url);
if ( !this.cache.has(url)) { const path = this.computePath(url);
this.cache.set(url, this.fetchDocument(url)); if ( !this.cache.has(path)) {
this.cache.set(path, this.fetchDocument(path));
} }
return this.cache.get(url); return this.cache.get(path);
} }
private fetchDocument(url: string) { private fetchDocument(path: string) {
const path = this.computePath(url);
this.logger.log('fetching document from', path); this.logger.log('fetching document from', path);
const subject = new AsyncSubject(); const subject = new AsyncSubject();
this.http this.http