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: () => {
//todo: figure out how to get single result set and $group $facets so I can fix this and improve resetStats
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': {
'_id': '$board',
'ips': {
'$sum': {
'$size': '$ips'
}
},
'pph': {
'$sum': '$pph'
},
'ips': {
'$addToSet': '$ips'
}
}
}, {
'$project': {
'ips': {
'$size': '$ips'
},
'pph': 1
}
}, {
'$merge': {
'into': 'boards'
}
}
]).toArray();
]);
},
//reset IP list for previous hour
resetIps: () => {
const hour = new Date();
return db.updateMany({
'hour': hour.setHours(hour.getHours()-1)
}, {
'$set': {
'ips': []
}
});
},
//reset all hours.
//TODO: implement a $facet with 2 groups in updateBoards so I can keep pph across hours
resetPph: () => {
return db.updateMany({}, {
'$set': {
'pph': 0,
'tph': 0
}
});
//reset stats, used at start of each hour
resetStats: () => {
return Promise.all([
db.updateMany({
'hour': new Date().getHours()
}, {
'$set': {
'ips': [],
}
}),
db.updateMany({}, {
'$set': {
'pph': 0,
'tph': 0
}
}),
]);
},
deleteBoard: (board) => {

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

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

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

Loading…
Cancel
Save