From 5d9ad017725fa599c8424e424ecf7f11a08eb0ec Mon Sep 17 00:00:00 2001 From: schneefux Date: Mon, 22 May 2017 12:38:34 +0200 Subject: implement player upcrunch --- server.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'server.js') diff --git a/server.js b/server.js index 4aa1936..19cfb74 100644 --- a/server.js +++ b/server.js @@ -299,14 +299,24 @@ async function updateSamples(region) { await setKey("samples_last_update", region, last_update); } -// wipe all points that meet the `where` condition and recrunch +// upcrunch player's stats async function crunchPlayer(api_id) { - logger.info("deleting all player points", { api_id: api_id }); - await model.PlayerPoint.destroy({ where: { player_api_id: api_id } }); + const last_crunch = await model.PlayerPoint.findOne({ + attributes: ["updated_at"], + where: { player_api_id: api_id }, + order: [ ["updated_at", "DESC"] ] + }), + last_crunch_date = last_crunch == undefined? + new Date(0) : last_crunch.updated_at; // get all participants for this player const participations = await model.Participant.findAll({ attributes: ["api_id"], - where: { player_api_id: api_id } }); + where: { + player_api_id: api_id, + created_at: { + $gt: last_crunch_date + } + } }); // send everything to cruncher logger.info("sending participations to cruncher", { length: participations.length }); -- cgit v1.3.1