Skip to content

Commit 9159e8f

Browse files
Merge pull request #2315 from hashicorp/optimizations
Website Speed Optimizations - Model Caching
2 parents e9866ff + e023fd7 commit 9159e8f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

website/app/routes/show.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,16 @@ export default class ShowRoute extends Route {
1919
},
2020
};
2121

22+
modelCache = {};
23+
2224
model(params) {
2325
// remove trailing slash
24-
let path = params.path.replace(/\/$/, '');
26+
const path = params.path.replace(/\/$/, '');
27+
28+
// If the model is cached, return it
29+
if (this.modelCache[path]) {
30+
return this.modelCache[path];
31+
}
2532

2633
// redirect if `index` is added to the URL
2734
if (path.endsWith('/index')) {
@@ -128,7 +135,7 @@ export default class ShowRoute extends Route {
128135
});
129136
}
130137

131-
return {
138+
this.modelCache[path] = {
132139
// IMPORTANT: this is the "component" ID which is used to get the correct backing class for the markdown "component"
133140
// This ID comes from the markdown-to-json conversion (see `id: relativePath.replace(/\.md$/, '')` in `addons/field-guide/lib/markdown-to-jsonapi.js`)
134141
id: res.data.id, // eg. 'components/alert/index'
@@ -141,6 +148,8 @@ export default class ShowRoute extends Route {
141148
hasSidecar,
142149
relatedComponents,
143150
};
151+
152+
return this.modelCache[path];
144153
});
145154
}
146155

0 commit comments

Comments
 (0)