diff --git a/DocService/sources/server.js b/DocService/sources/server.js index b3896ccb..7835619c 100644 --- a/DocService/sources/server.js +++ b/DocService/sources/server.js @@ -58,6 +58,7 @@ const commonDefines = require('./../../Common/sources/commondefines'); const operationContext = require('./../../Common/sources/operationContext'); const tenantManager = require('./../../Common/sources/tenantManager'); const staticRouter = require('./routes/static'); +const ms = require('ms'); const cfgWopiEnable = config.get('wopi.enable'); const cfgWopiDummyEnable = config.get('wopi.dummy.enable'); @@ -94,16 +95,12 @@ app.set("views", path.resolve(process.cwd(), cfgHtmlTemplate)); app.set("view engine", "ejs"); const server = http.createServer(app); -let licenseInfo, licenseOriginal, updatePluginsTime, userPlugins, pluginsLoaded; +let licenseInfo, licenseOriginal, updatePluginsTime, userPlugins; +const updatePluginsCacheExpire = ms("5m"); const updatePlugins = (eventType, filename) => { - operationContext.global.logger.info('update Folder: %s ; %s', eventType, filename); - if (updatePluginsTime && 1000 >= (new Date() - updatePluginsTime)) { - return; - } operationContext.global.logger.info('update Folder true: %s ; %s', eventType, filename); - updatePluginsTime = new Date(); - pluginsLoaded = false; + userPlugins = undefined; }; const readLicense = async function () { [licenseInfo, licenseOriginal] = await license.readLicense(cfgLicenseFile); @@ -299,12 +296,12 @@ docsCoServer.install(server, () => { }); const sendUserPlugins = (res, data) => { - pluginsLoaded = true; res.setHeader('Content-Type', 'application/json'); res.send(JSON.stringify(data)); }; app.get('/plugins.json', (req, res) => { - if (userPlugins && pluginsLoaded) { + //fs.watch is not reliable. Set cache expiry time + if (userPlugins && (new Date() - updatePluginsTime) < updatePluginsCacheExpire) { sendUserPlugins(res, userPlugins); return; } @@ -341,6 +338,7 @@ docsCoServer.install(server, () => { } } + updatePluginsTime = new Date(); userPlugins = {'url': '', 'pluginsData': result, 'autostart': pluginsAutostart}; sendUserPlugins(res, userPlugins); });