mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-08 16:05:05 -04:00
Cache etherpad informations for one hour
This commit is contained in:
parent
94ad1a594d
commit
43a7f53ddc
1 changed files with 13 additions and 3 deletions
|
@ -5,10 +5,17 @@ const axios = require('axios');
|
||||||
const headers = {
|
const headers = {
|
||||||
'User-Agent': 'Etherpad ' + settings.getEpVersion(),
|
'User-Agent': 'Etherpad ' + settings.getEpVersion(),
|
||||||
}
|
}
|
||||||
let infos;
|
|
||||||
|
|
||||||
const loadEtherpadInformations = () =>
|
const updateInterval = 60 * 60 * 1000; // 1 hour
|
||||||
axios.get('https://static.etherpad.org/info.json', {headers: headers})
|
let infos;
|
||||||
|
let lastLoadingTime = null;
|
||||||
|
|
||||||
|
const loadEtherpadInformations = () => {
|
||||||
|
if (lastLoadingTime !== null && Date.now() - lastLoadingTime < updateInterval) {
|
||||||
|
return Promise.resolve(infos);
|
||||||
|
}
|
||||||
|
|
||||||
|
return axios.get('https://static.etherpad.org/info.json', {headers: headers})
|
||||||
.then(async resp => {
|
.then(async resp => {
|
||||||
try {
|
try {
|
||||||
infos = await resp.data;
|
infos = await resp.data;
|
||||||
|
@ -16,11 +23,14 @@ const loadEtherpadInformations = () =>
|
||||||
await Promise.reject("Could not retrieve current version")
|
await Promise.reject("Could not retrieve current version")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lastLoadingTime = Date.now();
|
||||||
return await Promise.resolve(infos);
|
return await Promise.resolve(infos);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return await Promise.reject(err);
|
return await Promise.reject(err);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
exports.getLatestVersion = () => {
|
exports.getLatestVersion = () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue