mirror of
https://github.com/ONLYOFFICE/server.git
synced 2026-04-07 14:04:35 +08:00
[bug] Set cache expiry time for plugins.json request; For bug 71003
This commit is contained in:
@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user