summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2017-08-11 10:00:54 +0200
committerschneefux <schneefux+commit@schneefux.xyz>2017-08-11 10:00:54 +0200
commitbd406fab310831604f1fbce494ef0510c33cca1e (patch)
tree4d538420bed3ada9c280db0751637ed7a9c45fce
parent59c9119a66b693fbdf90164635010650bb1bf8a3 (diff)
downloadbridge-bd406fab310831604f1fbce494ef0510c33cca1e.tar.gz
bridge-bd406fab310831604f1fbce494ef0510c33cca1e.zip
cruncher_player endpoint, load using created_at
-rw-r--r--service_crunch.js11
1 files 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",