mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 23:46:14 -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
|
@ -36,7 +36,7 @@ exports.socketio = function (hook_name, args, cb) {
|
||||||
socket.on("checkUpdates", function() {
|
socket.on("checkUpdates", function() {
|
||||||
socket.emit("progress", {progress:0, message:'Checking for plugin updates...'});
|
socket.emit("progress", {progress:0, message:'Checking for plugin updates...'});
|
||||||
// Check plugins for updates
|
// Check plugins for updates
|
||||||
installer.search({offset: 0, pattern: '', limit: 500}, /*useCache:*/true, function(data) { // hacky
|
installer.search({offset: 0, pattern: '', limit: 500}, /*maxCacheAge:*/60*10, function(data) { // hacky
|
||||||
if (!data.results) return;
|
if (!data.results) return;
|
||||||
var updatable = _(plugins.plugins).keys().filter(function(plugin) {
|
var updatable = _(plugins.plugins).keys().filter(function(plugin) {
|
||||||
if(!data.results[plugin]) return false;
|
if(!data.results[plugin]) return false;
|
||||||
|
@ -51,7 +51,7 @@ exports.socketio = function (hook_name, args, cb) {
|
||||||
|
|
||||||
socket.on("search", function (query) {
|
socket.on("search", function (query) {
|
||||||
socket.emit("progress", {progress:0, message:'Fetching results...'});
|
socket.emit("progress", {progress:0, message:'Fetching results...'});
|
||||||
installer.search(query, true, function (progress) {
|
installer.search(query, /*maxCacheAge:*/60*10, function (progress) {
|
||||||
if (progress.results)
|
if (progress.results)
|
||||||
socket.emit("search-result", progress);
|
socket.emit("search-result", progress);
|
||||||
socket.emit("progress", progress);
|
socket.emit("progress", progress);
|
||||||
|
|
|
@ -163,8 +163,10 @@ $(document).ready(function () {
|
||||||
}
|
}
|
||||||
updateHandlers();
|
updateHandlers();
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
socket.emit('checkUpdates');
|
socket.emit('checkUpdates');
|
||||||
tasks++;
|
tasks++;
|
||||||
|
}, 5000)
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('updatable', function(data) {
|
socket.on('updatable', function(data) {
|
||||||
|
|
|
@ -71,12 +71,13 @@ exports.install = function(plugin_name, cb) {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.searchCache = null;
|
exports.searchCache = null;
|
||||||
|
var cacheTimestamp = 0;
|
||||||
|
|
||||||
exports.search = function(query, cache, cb) {
|
exports.search = function(query, maxCacheAge, cb) {
|
||||||
withNpm(
|
withNpm(
|
||||||
function (cb) {
|
function (cb) {
|
||||||
var getData = 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);
|
cb(null, exports.searchCache);
|
||||||
} else {
|
} else {
|
||||||
registry.get(
|
registry.get(
|
||||||
|
@ -84,6 +85,7 @@ exports.search = function(query, cache, cb) {
|
||||||
function (er, data) {
|
function (er, data) {
|
||||||
if (er) return cb(er);
|
if (er) return cb(er);
|
||||||
exports.searchCache = data;
|
exports.searchCache = data;
|
||||||
|
cacheTimestamp = Math.round(+new Date/1000)
|
||||||
cb(er, data);
|
cb(er, data);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue