Skip to content

Commit

Permalink
fix profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
howardchung committed Jun 12, 2016
1 parent bfd4e68 commit cb85f25
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 34 deletions.
1 change: 1 addition & 0 deletions sql/create_tables.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CREATE EXTENSION pg_trgm;
CREATE EXTENSION tsm_system_rows;

CREATE TABLE matches (
match_id bigint PRIMARY KEY,
Expand Down
56 changes: 22 additions & 34 deletions svc/profiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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);
});
});
}

0 comments on commit cb85f25

Please sign in to comment.