Skip to content

Commit

Permalink
[bug] Set cache expiry time for plugins.json request; For bug 71003
Browse files Browse the repository at this point in the history
  • Loading branch information
konovalovsergey committed Oct 17, 2024
1 parent ddd3601 commit 12a0963
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions DocService/sources/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -341,6 +338,7 @@ docsCoServer.install(server, () => {
}
}

updatePluginsTime = new Date();
userPlugins = {'url': '', 'pluginsData': result, 'autostart': pluginsAutostart};
sendUserPlugins(res, userPlugins);
});
Expand Down

0 comments on commit 12a0963

Please sign in to comment.