summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2017-04-03 16:03:58 +0200
committerschneefux <schneefux+commit@schneefux.xyz>2017-04-03 16:03:58 +0200
commit26e651c824be2f412356b02dd71538afc953bd24 (patch)
tree7e904fc322bc74e7e039537796fdb1f4a3a5b133
parente759378816bd9edd5243097a0047320f6330af49 (diff)
downloadshrinker-26e651c824be2f412356b02dd71538afc953bd24.tar.gz
shrinker-26e651c824be2f412356b02dd71538afc953bd24.zip
handle players and matches seperately
-rw-r--r--worker.js21
1 files changed, 16 insertions, 5 deletions
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)) {