summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2017-05-22 12:38:34 +0200
committerschneefux <schneefux+commit@schneefux.xyz>2017-05-22 12:38:34 +0200
commit5d9ad017725fa599c8424e424ecf7f11a08eb0ec (patch)
tree0517d2388003457cff9185d0e1b634f771277269
parent1125651395fa2f6666ef8da04726f6a07919740f (diff)
downloadbridge-5d9ad017725fa599c8424e424ecf7f11a08eb0ec.tar.gz
bridge-5d9ad017725fa599c8424e424ecf7f11a08eb0ec.zip
implement player upcrunchrelease/2.4.0
-rw-r--r--server.js18
1 files changed, 14 insertions, 4 deletions
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 });