mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-25 09:56:15 -04:00
Fix caching of npm search results and only make one registry request on /admin/plugins
fixes #1488
This commit is contained in:
parent
ef7fb5c7f0
commit
0070eab416
3 changed files with 10 additions and 6 deletions
|
@ -163,8 +163,10 @@ $(document).ready(function () {
|
|||
}
|
||||
updateHandlers();
|
||||
|
||||
socket.emit('checkUpdates');
|
||||
tasks++;
|
||||
setTimeout(function() {
|
||||
socket.emit('checkUpdates');
|
||||
tasks++;
|
||||
}, 5000)
|
||||
});
|
||||
|
||||
socket.on('updatable', function(data) {
|
||||
|
|
|
@ -71,12 +71,13 @@ exports.install = function(plugin_name, cb) {
|
|||
};
|
||||
|
||||
exports.searchCache = null;
|
||||
var cacheTimestamp = 0;
|
||||
|
||||
exports.search = function(query, cache, cb) {
|
||||
exports.search = function(query, maxCacheAge, cb) {
|
||||
withNpm(
|
||||
function (cb) {
|
||||
var getData = function (cb) {
|
||||
if (cache && exports.searchCache) {
|
||||
if (maxCacheAge && exports.searchCache && Math.round(+new Date/1000)-cacheTimestamp < maxCacheAge) {
|
||||
cb(null, exports.searchCache);
|
||||
} else {
|
||||
registry.get(
|
||||
|
@ -84,6 +85,7 @@ exports.search = function(query, cache, cb) {
|
|||
function (er, data) {
|
||||
if (er) return cb(er);
|
||||
exports.searchCache = data;
|
||||
cacheTimestamp = Math.round(+new Date/1000)
|
||||
cb(er, data);
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue