Le mirroring des dépôts vers Github est maintenant natif dans Gitlab (et donc Framagit). Merci de passer à la fonction native pour que nous puissions couper notre solution maison. Détails sur https://docs.gitlab.com/ee/workflow/repository_mirroring.html#pushing-to-a-remote-repository (pensez à supprimer le webhook de notre solution maison).

Commit 18b55578 by Luc Didry

Better way to fill and update the blankPads cache

parent eb34080b
......@@ -8,6 +8,11 @@ The result is a json string like:
{"timestamp": 1425992868, "padsCount": 2, "blankPads": 1}
```
The `blankPads` counter may be inaccurate at Etherpad startup since the plugin fills a cache asynchronously.
After the startup, the cache is updated in real time (on pad creation, update or deletion) so it's always accurate.
If you have too many pads, Etherpad may not be able to list all pads. As this plugin relies on listAllPads API call, it will fail.
# License
Copyright 2015 Luc Didry
......
......@@ -3,7 +3,10 @@
{
"name": "ep_pads_stats",
"hooks": {
"expressCreateServer" : "ep_pads_stats/index:registerRoute"
"expressCreateServer" : "ep_pads_stats/index:registerRoute",
"padLoad" : "ep_pads_stats/index:padLoad",
"padUpdate" : "ep_pads_stats/index:padUpdate",
"padRemove" : "ep_pads_stats/index:padRemove"
}
}
]
......
var eejs = require('ep_etherpad-lite/node/eejs/'),
padManager = require('ep_etherpad-lite/node/db/PadManager'),
var API = require('ep_etherpad-lite/node/db/API'),
ERR = require('ep_etherpad-lite/node_modules/async-stacktrace'),
async = require('ep_etherpad-lite/node_modules/async');
// What about a little cache variable :-)
var blankPads = {};
async.waterfall([
function(callback){
padManager.listAllPads(callback)
},
function(data, callback) {
for (var pad in data.padIDs) {
padManager.getPad(data.padIDs[pad], function(err, data) {
if (data.getHeadRevisionNumber() == 0) {
blankPads[data.id] = 1;
} else {
delete blankPads[data.id];
}
});
var q = async.queue(function (pad, cb) {
if (blankPads[pad] === undefined) {
API.getRevisionsCount(pad, cb);
} else {
cb && cb();
}
}, 10);
// We need to update the cache on some events
exports.padLoad = function (hook_name, context, cb) {
var pad = context.pad;
if (pad.head === 0) {
blankPads[pad.id] = 1;
} else {
if (blankPads[pad.id] !== undefined) {
delete blankPads[pad.id];
}
callback(null, data.padIDs.length);
}
]);
cb && cb();
}
exports.padRemove = function (hook_name, context, cb) {
var padId = context.padID;
if (blankPads[padId] !== undefined) {
delete blankPads[padId];
}
cb && cb();
}
exports.padUpdate = function (hook_name, context, cb) {
var pad = context.pad;
if (pad.head === 0) {
blankPads[pad.id] = 1;
} else {
if (blankPads[pad.id] !== undefined) {
delete blankPads[pad.id];
}
}
cb && cb();
}
// At startup
exports.registerRoute = function (hook_name, args, cb) {
// Let's fill the blankPads var
API.listAllPads(function(err, data) {
async.each(data.padIDs, function(pad, cb) {
q.push(pad, cb);
});
});
// Answer to the route
args.app.get('/stats.json', function(req, res) {
var pads = [];
var data = [];
async.waterfall([
function(callback){
padManager.listAllPads(callback)
},
function(data, callback) {
for (var pad in data.padIDs) {
padManager.getPad(data.padIDs[pad], function(err, data) {
if (data.getHeadRevisionNumber() == 0) {
blankPads[data.id] = 1;
} else {
delete blankPads[data.id];
}
});
}
callback(null, data.padIDs.length);
},
function(data, callback) {
var timestamp = (new Date).getTime() / 1000 | 0;
res.setHeader('Content-Type', 'application/json');
res.send('{"timestamp": '+timestamp+', "padsCount": '+data+', "blankPads": '+Object.keys(blankPads).length+'}');
callback();
}
]);
API.listAllPads(function(err, data) {
var timestamp = (new Date).getTime() / 1000 | 0;
res.setHeader('Content-Type', 'application/json');
res.send('{"timestamp": '+timestamp+', "padsCount": '+data.padIDs.length+', "blankPads": '+Object.keys(blankPads).length+'}');
cb && cb();
});
});
};
{
"name": "ep_pads_stats",
"version": "0.0.7",
"description": "Adds an url to get some stats about the Etherpad lite instance",
"version": "0.0.8",
"description": "Adds an url to get some stats about the Etherpad instance",
"author": {
"name": "Luc Didry",
"email": "luc@didry.org",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment