From 5af53922ed4a6958802ab2623bc9f63e4a98100f Mon Sep 17 00:00:00 2001 From: Michael Shanks Date: Wed, 25 Mar 2020 12:38:04 +0000 Subject: [PATCH] evict packages from cache on SaveBackend --- .../builder/src/builderStore/store/backend.js | 2 +- packages/server/middleware/routers.js | 1 + packages/server/utilities/createAppPackage.js | 18 +++++++++++++++--- packages/server/utilities/masterAppInternal.js | 8 +++++++- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/packages/builder/src/builderStore/store/backend.js b/packages/builder/src/builderStore/store/backend.js index f6051dd4ba..e93fbe4733 100644 --- a/packages/builder/src/builderStore/store/backend.js +++ b/packages/builder/src/builderStore/store/backend.js @@ -183,7 +183,7 @@ export const saveCurrentNode = store => () => { const defaultIndex = templateApi(state.hierarchy).getNewIndexTemplate( cloned.parent() ) - defaultIndex.name = `all_${cloned.name}` + defaultIndex.name = `all_${cloned.name}s` defaultIndex.allowedRecordNodeIds = [cloned.nodeId] } diff --git a/packages/server/middleware/routers.js b/packages/server/middleware/routers.js index 00e2deff9c..b41fdeeb52 100644 --- a/packages/server/middleware/routers.js +++ b/packages/server/middleware/routers.js @@ -171,6 +171,7 @@ module.exports = (config, app) => { ctx.request.body.appDefinition, ctx.request.body.accessLevels ) + ctx.master.deleteLatestPackageFromCache(ctx.params.appname) ctx.response.status = StatusCodes.OK }) .post("/_builder/api/:appname/pages/:pageName", async ctx => { diff --git a/packages/server/utilities/createAppPackage.js b/packages/server/utilities/createAppPackage.js index 3aaa6ce09f..9a993a4ae4 100644 --- a/packages/server/utilities/createAppPackage.js +++ b/packages/server/utilities/createAppPackage.js @@ -5,12 +5,16 @@ const { getRuntimePackageDirectory } = require("../utilities/runtimePackages") const injectPlugins = require("./injectedPlugins") const { cwd } = require("process") +const appDefinitionPath = appPath => join(appPath, "appDefinition.json") +const pluginsPath = appPath => join(appPath, "plugins.js") +const accessLevelsPath = appPath => join(appPath, "access_levels.json") + const createAppPackage = (context, appPath) => { - const appDefModule = require(join(appPath, "appDefinition.json")) + const appDefModule = require(appDefinitionPath(appPath)) - const pluginsModule = require(join(appPath, "plugins.js")) + const pluginsModule = require(pluginsPath(appPath)) - const accessLevels = require(join(appPath, "access_levels.json")) + const accessLevels = require(accessLevelsPath(appPath)) return { appDefinition: appDefModule, @@ -87,3 +91,11 @@ module.exports.applictionVersionPackage = async ( await injectPlugins(pkg, context.master, appname, instanceKey) return pkg } + +module.exports.deleteCachedPackage = (context, appname, versionId) => { + const appPath = applictionVersionPath(context, appname, versionId) + + delete require.cache[resolve(appDefinitionPath(appPath))] + delete require.cache[resolve(pluginsPath(appPath))] + delete require.cache[resolve(accessLevelsPath(appPath))] +} diff --git a/packages/server/utilities/masterAppInternal.js b/packages/server/utilities/masterAppInternal.js index 88a7bdfb75..e02862f61c 100644 --- a/packages/server/utilities/masterAppInternal.js +++ b/packages/server/utilities/masterAppInternal.js @@ -11,8 +11,9 @@ const { masterAppPackage, applictionVersionPackage, applictionVersionPublicPaths, + deleteCachedPackage, } = require("../utilities/createAppPackage") -const { determineVersionId } = require("./runtimePackages") +const { determineVersionId, LATEST_VERSIONID } = require("./runtimePackages") const isMaster = appname => appname === "_master" @@ -345,6 +346,10 @@ module.exports = async context => { await bb.recordApi.save(userInMaster) } + const deleteLatestPackageFromCache = (appname) => { + deleteCachedPackage(context, appname, LATEST_VERSIONID) + } + const listApplications = () => values(applications) return { @@ -364,5 +369,6 @@ module.exports = async context => { getFullAccessApiForInstanceId, getFullAccessApiForMaster, getApplicationWithInstances, + deleteLatestPackageFromCache, } }