evict packages from cache on SaveBackend

This commit is contained in:
Michael Shanks 2020-03-25 12:38:04 +00:00
parent ecf5015c36
commit ca6c3d182a
4 changed files with 24 additions and 5 deletions

View File

@ -183,7 +183,7 @@ export const saveCurrentNode = store => () => {
const defaultIndex = templateApi(state.hierarchy).getNewIndexTemplate( const defaultIndex = templateApi(state.hierarchy).getNewIndexTemplate(
cloned.parent() cloned.parent()
) )
defaultIndex.name = `all_${cloned.name}` defaultIndex.name = `all_${cloned.name}s`
defaultIndex.allowedRecordNodeIds = [cloned.nodeId] defaultIndex.allowedRecordNodeIds = [cloned.nodeId]
} }

View File

@ -171,6 +171,7 @@ module.exports = (config, app) => {
ctx.request.body.appDefinition, ctx.request.body.appDefinition,
ctx.request.body.accessLevels ctx.request.body.accessLevels
) )
ctx.master.deleteLatestPackageFromCache(ctx.params.appname)
ctx.response.status = StatusCodes.OK ctx.response.status = StatusCodes.OK
}) })
.post("/_builder/api/:appname/pages/:pageName", async ctx => { .post("/_builder/api/:appname/pages/:pageName", async ctx => {

View File

@ -5,12 +5,16 @@ const { getRuntimePackageDirectory } = require("../utilities/runtimePackages")
const injectPlugins = require("./injectedPlugins") const injectPlugins = require("./injectedPlugins")
const { cwd } = require("process") 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 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 { return {
appDefinition: appDefModule, appDefinition: appDefModule,
@ -87,3 +91,11 @@ module.exports.applictionVersionPackage = async (
await injectPlugins(pkg, context.master, appname, instanceKey) await injectPlugins(pkg, context.master, appname, instanceKey)
return pkg 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))]
}

View File

@ -11,8 +11,9 @@ const {
masterAppPackage, masterAppPackage,
applictionVersionPackage, applictionVersionPackage,
applictionVersionPublicPaths, applictionVersionPublicPaths,
deleteCachedPackage,
} = require("../utilities/createAppPackage") } = require("../utilities/createAppPackage")
const { determineVersionId } = require("./runtimePackages") const { determineVersionId, LATEST_VERSIONID } = require("./runtimePackages")
const isMaster = appname => appname === "_master" const isMaster = appname => appname === "_master"
@ -345,6 +346,10 @@ module.exports = async context => {
await bb.recordApi.save(userInMaster) await bb.recordApi.save(userInMaster)
} }
const deleteLatestPackageFromCache = (appname) => {
deleteCachedPackage(context, appname, LATEST_VERSIONID)
}
const listApplications = () => values(applications) const listApplications = () => values(applications)
return { return {
@ -364,5 +369,6 @@ module.exports = async context => {
getFullAccessApiForInstanceId, getFullAccessApiForInstanceId,
getFullAccessApiForMaster, getFullAccessApiForMaster,
getApplicationWithInstances, getApplicationWithInstances,
deleteLatestPackageFromCache,
} }
} }