Skip to content

Commit a6823cf

Browse files
committed
Cache URL derivation during generation
Resolves #2386 Co-Authored-By: @ajesshope
1 parent 1f88a1f commit a6823cf

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- TypeDoc will now attempt to cache icons when `DefaultThemeRenderContext.icons` is overwritten by a custom theme.
1313
Note: To perform this optimization, TypeDoc relies on `DefaultThemeRenderContext.iconCache` being rendered within
1414
each page. TypeDoc does it in the `defaultLayout` template.
15+
- Cache URL derivation during generation, #2386.
1516

1617
### Bug Fixes
1718

@@ -24,6 +25,7 @@
2425

2526
### Thanks!
2627

28+
- @ajesshope
2729
- @HemalPatil
2830
- @hrueger
2931
- @typhonrt

src/lib/output/components.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ export abstract class ContextAwareRendererComponent extends RendererComponent {
4646
this.listenTo(this.owner, {
4747
[RendererEvent.BEGIN]: this.onBeginRenderer,
4848
[PageEvent.BEGIN]: this.onBeginPage,
49+
[RendererEvent.END]: () => this.absoluteToRelativePathMap.clear(),
4950
});
5051
}
5152

53+
private absoluteToRelativePathMap = new Map<string, string>();
54+
5255
/**
5356
* Transform the given absolute path into a relative path.
5457
*
@@ -59,7 +62,12 @@ export abstract class ContextAwareRendererComponent extends RendererComponent {
5962
if (this.urlPrefix.test(absolute)) {
6063
return absolute;
6164
} else {
62-
return Path.posix.relative(this.location, absolute) || ".";
65+
const key = `${this.location}:${absolute}`;
66+
let path = this.absoluteToRelativePathMap.get(key);
67+
if (path) return path;
68+
path = Path.posix.relative(this.location, absolute) || ".";
69+
this.absoluteToRelativePathMap.set(key, path);
70+
return path;
6371
}
6472
}
6573

0 commit comments

Comments
 (0)