From bd406fab310831604f1fbce494ef0510c33cca1e Mon Sep 17 00:00:00 2001 From: schneefux Date: Fri, 11 Aug 2017 10:00:54 +0200 Subject: cruncher_player endpoint, load using created_at --- service_crunch.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/service_crunch.js b/service_crunch.js index 2de15d5..bc067ff 100644 --- a/service_crunch.js +++ b/service_crunch.js @@ -54,14 +54,21 @@ module.exports = class Cruncher extends Service { // upcrunch player's stats async crunchPlayer(category, api_id) { const db = this.getDatabase(category), - where = { player_api_id: api_id }; + where = { player_api_id: api_id }, + last_crunch_r = await db.PlayerPoint.findOne({ + attributes: [ "updated_at" ], // stores max created_at + where, + order: [ ["updated_at", "DESC"] ] + }); + if (last_crunch_r) where.created_at = { $gt: last_crunch_r.updated_at }; // wipe previous calculations await db.PlayerPoint.destroy({ where }); // get all participants for this player const participations = await db.Participant.findAll({ attributes: [ "api_id" ], - where + where, + order: [ ["created_at", "ASC" ] ] }); // send everything to cruncher logger.info("sending participations to cruncher", -- cgit v1.3.1