Skip to content

Commit 532b418

Browse files
Cache the assets locations
1 parent d6c1a56 commit 532b418

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

lib/manage-prototype-handlers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function postPasswordHandler (req, res) {
119119
}
120120
}
121121

122-
function managePluginsMiddleware (req, res, next) {
122+
function managePrototypeMiddleware (req, res, next) {
123123
const { scripts: frontEndScripts } = getScriptsAndAssetsConfig(getInternalGovukFrontendDir())
124124
const { scripts: kitScripts } = getScriptsAndAssetsConfig(packageDir)
125125
res.locals.managePlugins = {
@@ -744,7 +744,7 @@ async function postPluginsModeHandler (req, res) {
744744

745745
module.exports = {
746746
contextPath,
747-
managePluginsMiddleware,
747+
managePrototypeMiddleware,
748748
setKitRestarted,
749749
csrfProtection: [doubleCsrfProtection, csrfErrorHandler],
750750
getPageLoadedHandler,

lib/manage-prototype-routes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const express = require('express')
66

77
const {
88
contextPath,
9-
managePluginsMiddleware,
9+
managePrototypeMiddleware,
1010
setKitRestarted,
1111
csrfProtection,
1212
getPageLoadedHandler,
@@ -36,7 +36,7 @@ const { govukFrontendPaths } = require('./govukFrontendPaths')
3636

3737
const router = require('../index').requests.setupRouter(contextPath)
3838

39-
router.use(managePluginsMiddleware)
39+
router.use(managePrototypeMiddleware)
4040

4141
function getAssetUrls (pluginDir) {
4242
const { scripts, assets } = getScriptsAndAssetsConfig(pluginDir)

lib/utils/index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,12 @@ async function searchAndReplaceFiles (dir, searchText, replaceText, extensions)
253253
return modifiedFiles.flat().filter(Boolean)
254254
}
255255

256+
const managePrototypeCache = {}
257+
256258
function getScriptsAndAssetsConfig (pluginDir) {
259+
if (managePrototypeCache[pluginDir]) {
260+
return managePrototypeCache[pluginDir]
261+
}
257262
let {
258263
assets = [],
259264
scripts = []
@@ -267,7 +272,8 @@ function getScriptsAndAssetsConfig (pluginDir) {
267272
scripts = [scripts]
268273
}
269274

270-
return { assets, scripts }
275+
managePrototypeCache[pluginDir] = { assets, scripts }
276+
return managePrototypeCache[pluginDir]
271277
}
272278

273279
function sortByObjectKey (key) {

0 commit comments

Comments
 (0)