From d325d3126d49ddf8dbb4631b441844b8d7b580b6 Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Wed, 17 Jul 2013 22:55:50 -0400 Subject: [PATCH] Hopefully shed some light on stats issue --- acp.js | 2 +- stats.js | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/acp.js b/acp.js index 12ad6e9e..0a0650a0 100644 --- a/acp.js +++ b/acp.js @@ -165,7 +165,7 @@ module.exports = function (Server) { var db = Server.db.getConnection(); if(!db) return; - var query = "SELECT * FROM stats WHERE 1"; + var query = "SELECT * FROM stats ORDER BY time ASC"; var results = db.querySync(query); if(results) user.socket.emit("acp-view-stats", results.fetchAllSync()); diff --git a/stats.js b/stats.js index 9812b08b..04349990 100644 --- a/stats.js +++ b/stats.js @@ -9,8 +9,12 @@ The above copyright notice and this permission notice shall be included in all c THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +var Logger = require("./logger"); + +const STAT_INTERVAL = 60 * 60 * 1000; +const STAT_EXPIRE = 24 * STAT_INTERVAL; + module.exports = function (Server) { - // Check every 60 minutes setInterval(function () { var chancount = Server.channels.length; var usercount = 0; @@ -29,14 +33,20 @@ module.exports = function (Server) { [Date.now(), usercount, chancount, mem] ); - db.querySync(query); + if(!db.querySync(query)) { + Logger.errlog.log("! Failed to record stats"); + Logger.errlog.log(query); + } query = Server.db.createQuery( "DELETE FROM stats WHERE time