From 92296feb3f994740ca1265a0d0edf2857eb65fba Mon Sep 17 00:00:00 2001 From: Sergey Konovalov Date: Thu, 17 Oct 2024 10:45:38 +0300 Subject: [PATCH] [bug] Set cache expiry time for plugins.json request; For bug 71003 --- DocService/sources/server.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/DocService/sources/server.js b/DocService/sources/server.js index 9a163058..32918edb 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); @@ -295,12 +292,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; } @@ -337,6 +334,7 @@ docsCoServer.install(server, () => { } } + updatePluginsTime = new Date(); userPlugins = {'url': '', 'pluginsData': result, 'autostart': pluginsAutostart}; sendUserPlugins(res, userPlugins); });