diff --git a/sql/create_tables.sql b/sql/create_tables.sql index 041f97d49..134bda3f7 100644 --- a/sql/create_tables.sql +++ b/sql/create_tables.sql @@ -1,4 +1,5 @@ CREATE EXTENSION pg_trgm; +CREATE EXTENSION tsm_system_rows; CREATE TABLE matches ( match_id bigint PRIMARY KEY, diff --git a/svc/profiler.js b/svc/profiler.js index a6d13b44f..68582f244 100644 --- a/svc/profiler.js +++ b/svc/profiler.js @@ -8,7 +8,6 @@ var utility = require('../util/utility'); var insertPlayer = queries.insertPlayer; var getData = utility.getData; var async = require('async'); -var max; start(); function start() @@ -25,49 +24,38 @@ function start() function getSummaries(cb) { - db.raw(`select max(match_id) from matches`).asCallback(function(err, result) + db.raw(` + SELECT account_id + FROM players + TABLESAMPLE SYSTEM_ROWS(100) + `).asCallback(function(err, results) { if (err) { return cb(err); } - max = Number(result.rows[0].max); - var min = max - 10000000; - db.raw(` - select distinct account_id - from player_matches - where match_id in (SELECT (?::bigint + random()*(?::bigint - ?::bigint))::bigint as rand - from generate_series(1,50)) - and account_id < ? limit 100 - `, [min, max, min, constants.anonymous_account_id]).asCallback(function(err, results) + if (results.rows.length === 0) + { + console.log('No account_ids found...'); + return cb(); + } + console.log('players sampled: %s', results.rows.length); + var container = utility.generateJob("api_summaries", + { + players: results.rows + }); + getData(container.url, function(err, body) { if (err) { - return cb(err); + //couldn't get data from api, non-retryable + return cb(JSON.stringify(err)); } - if (results.rows.length === 0) - { - console.log('No account_ids found...'); - return cb(); - } - console.log('players sampled: %s', results.rows.length); - var container = utility.generateJob("api_summaries", - { - players: results.rows - }); - getData(container.url, function(err, body) + //player summaries response + async.each(body.response.players, function(player, cb) { - if (err) - { - //couldn't get data from api, non-retryable - return cb(JSON.stringify(err)); - } - //player summaries response - async.each(body.response.players, function(player, cb) - { - insertPlayer(db, player, cb); - }, cb); - }); + insertPlayer(db, player, cb); + }, cb); }); }); }