Skip to content

Commit

Permalink
Cache the assets locations
Browse files Browse the repository at this point in the history
  • Loading branch information
BenSurgisonGDS committed Sep 11, 2023
1 parent de70b80 commit 03bd181
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/manage-prototype-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function postPasswordHandler (req, res) {
}
}

function managePluginsMiddleware (req, res, next) {
function managePrototypeMiddleware (req, res, next) {
const { scripts: frontEndScripts } = getScriptsAndAssetsConfig(getInternalGovukFrontendDir())
const { scripts: kitScripts } = getScriptsAndAssetsConfig(packageDir)
res.locals.managePlugins = {
Expand Down Expand Up @@ -744,7 +744,7 @@ async function postPluginsModeHandler (req, res) {

module.exports = {
contextPath,
managePluginsMiddleware,
managePrototypeMiddleware,
setKitRestarted,
csrfProtection: [doubleCsrfProtection, csrfErrorHandler],
getPageLoadedHandler,
Expand Down
4 changes: 2 additions & 2 deletions lib/manage-prototype-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const express = require('express')

const {
contextPath,
managePluginsMiddleware,
managePrototypeMiddleware,
setKitRestarted,
csrfProtection,
getPageLoadedHandler,
Expand Down Expand Up @@ -36,7 +36,7 @@ const { packageDir } = require('./utils/paths')

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

router.use(managePluginsMiddleware)
router.use(managePrototypeMiddleware)

function getAssetUrls (pluginDir) {
const { scripts, assets } = getScriptsAndAssetsConfig(pluginDir)
Expand Down
8 changes: 7 additions & 1 deletion lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,12 @@ function getInternalGovukFrontendDir () {
return internalGovukFrontendDir
}

const managePrototypeCache = {}

function getScriptsAndAssetsConfig (pluginDir) {
if (managePrototypeCache[pluginDir]) {
return managePrototypeCache[pluginDir]
}
let {
assets = [],
scripts = []
Expand All @@ -278,7 +283,8 @@ function getScriptsAndAssetsConfig (pluginDir) {
scripts = [scripts]
}

return { assets, scripts }
managePrototypeCache[pluginDir] = { assets, scripts }
return managePrototypeCache[pluginDir]
}

function sortByObjectKey (key) {
Expand Down

0 comments on commit 03bd181

Please sign in to comment.