-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpurge.js
41 lines (35 loc) · 1.13 KB
/
purge.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* Created by wbison on 04-05-15.
*/
module.exports = function(config) {
var request = require('./purgerequest')(config);
var _ = require('underscore');
var log = require('./log')(config);
return function(db, cb) {
db.view(config._design_doc._id, '_default', { limit: 10000 }, function(e,b) {
if (e) { return cb(e); }
var r = {};
_(b.rows).each(function(row) {
r[row.key] = [row.value];
});
if (b.rows.length) {
if (config.testrun) {
log(db, "Purgable " + b.rows.length + " documents");
}
else {
log(db, "Purging " + b.rows.length + " documents");
request(db, r, function (err, b) {
if (err) {
return cb(err);
}
db.compact(function (err, b) {
});
});
}
}
else {
log(db, "Nothing to purge");
}
});
}
}