From 26e651c824be2f412356b02dd71538afc953bd24 Mon Sep 17 00:00:00 2001 From: schneefux Date: Mon, 3 Apr 2017 16:03:58 +0200 Subject: handle players and matches seperately --- worker.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'worker.js') diff --git a/worker.js b/worker.js index 0e528b5..65befbc 100644 --- a/worker.js +++ b/worker.js @@ -73,6 +73,10 @@ var RABBITMQ_URI = process.env.RABBITMQ_URI || "amqp://localhost", return o; } + // helper: true if object is not in record arr + let is_in = (arr, obj) => arr.map((o) => o.api_id).indexOf(obj.api_id) > -1; + + // we aggregate record objects to do a bulk insert let match_records = [], roster_records = [], @@ -82,7 +86,18 @@ var RABBITMQ_URI = process.env.RABBITMQ_URI || "amqp://localhost", participant_item_records = []; // populate `_records` - msgs.map((msg) => { + // data from `/player` + msgs.filter((m) => m.properties.type == "player").map((msg) => { + let players = JSON.parse(msg.content); + players.map(async (p) => { + player = flatten(p); + if (!is_in(player_records, p.player)) + player_records.push(p.player); + }); + }); + + // data from `/matches` + msgs.filter((m) => m.properties.type == "match").map((msg) => { let match = JSON.parse(msg.content); console.log("processing match", match.id); @@ -155,10 +170,6 @@ var RABBITMQ_URI = process.env.RABBITMQ_URI || "amqp://localhost", match = snakeCaseKeys(flatten(match)); // after conversion, create the array of records - // - // helper: true if object is not in record arr - let is_in = (arr, obj) => arr.map((o) => o.api_id).indexOf(obj.api_id) > -1; - // there is a low chance of a match being duplicated in a batch, // skip it and its children if (!is_in(match_records, match)) { -- cgit v1.3.1