more scuffed stats changes:

merge-requests/208/head
fatchan 5 years ago
parent d9559c76e6
commit c8acbaae04
  1. 63
      db/stats.js
  2. 3
      helpers/build.js
  3. 2
      models/forms/actionhandler.js
  4. 2
      schedules.js

@ -37,48 +37,57 @@ module.exports = {
}, },
updateBoards: () => { updateBoards: () => {
//todo: figure out how to get single result set and $group $facets so I can fix this and improve resetStats
return db.aggregate([ return db.aggregate([
{ {
'$unwind': {
'path': '$ips',
'preserveNullAndEmptyArrays': true
//provides empty array instead of null so that $project stage $size will work and
//update dead boards back to 0 ips
}
}, {
'$group': { '$group': {
'_id': '$board', '_id': '$board',
'ips': {
'$sum': {
'$size': '$ips'
}
},
'pph': { 'pph': {
'$sum': '$pph' '$sum': '$pph'
},
'ips': {
'$addToSet': '$ips'
} }
} }
}, {
'$project': {
'ips': {
'$size': '$ips'
},
'pph': 1
}
}, { }, {
'$merge': { '$merge': {
'into': 'boards' 'into': 'boards'
} }
} }
]).toArray(); ]);
}, },
//reset IP list for previous hour //reset stats, used at start of each hour
resetIps: () => { resetStats: () => {
const hour = new Date(); return Promise.all([
return db.updateMany({ db.updateMany({
'hour': hour.setHours(hour.getHours()-1) 'hour': new Date().getHours()
}, { }, {
'$set': { '$set': {
'ips': [] 'ips': [],
} }
}); }),
}, db.updateMany({}, {
'$set': {
//reset all hours. 'pph': 0,
//TODO: implement a $facet with 2 groups in updateBoards so I can keep pph across hours 'tph': 0
resetPph: () => { }
return db.updateMany({}, { }),
'$set': { ]);
'pph': 0,
'tph': 0
}
});
}, },
deleteBoard: (board) => { deleteBoard: (board) => {

@ -196,8 +196,7 @@ module.exports = {
const label = 'Hourly stats rollover'; const label = 'Hourly stats rollover';
const start = process.hrtime(); const start = process.hrtime();
await Stats.updateBoards(); await Stats.updateBoards();
await Stats.resetPph(); await Stats.resetStats();
await Stats.resetIps();
const end = process.hrtime(start); const end = process.hrtime(start);
console.log(timeDiffString(label, end)); console.log(timeDiffString(label, end));
}, },

@ -134,7 +134,7 @@ module.exports = async (req, res, next) => {
if (action) { if (action) {
if (req.body.unlink_file) { if (req.body.unlink_file) {
modlogActions.push('Unlink files'); modlogActions.push('Unlink files');
} else if () { } else if (req.body.delete_file) {
modlogActions.push('Delete files'); modlogActions.push('Delete files');
} }
aggregateNeeded = true; aggregateNeeded = true;

@ -43,7 +43,7 @@ const msTime = require(__dirname+'/helpers/mstime.js')
'options': {} 'options': {}
}, { }, {
'repeat': { 'repeat': {
'cron': '1 * * * *' 'cron': '0 * * * *'
} }
}); });

Loading…
Cancel
Save