Skip to content

Commit

Permalink
db timing stats in server
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenhao committed Sep 11, 2020
1 parent d088cee commit e42fb88
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,25 @@ class GameModel {

async getEvents(gid) {
if (!this.connected) throw new Error('not connected');
console.log('[GameModel] listing events', gid);
const startTime = Date.now();
const res = await this.client.query('SELECT event_payload FROM game_events WHERE gid=$1', [gid]);
// const serializedEvents = await client.lrangeAsync(getEventsKey(gid), 0, MAX_EVENTS);
const events = _.map(res.rows, 'event_payload');
const ms = Date.now() - startTime;
console.log(`getEvents(${gid}) took ${ms}ms`);
return events;
}

async addEvent(gid, event) {
if (!this.connected) throw new Error('not connected');
console.log('[GameModel] Persisting event', gid, event.type);
const startTime = Date.now();
await this.client.query(
`
INSERT INTO game_events (gid, uid, ts, event_type, event_payload)
VALUES ($1, $2, $3, $4, $5)`,
[gid, event.user, new Date(event.timestamp).toISOString(), event.type, event]
);
const ms = Date.now() - startTime;
console.log(`addEvent(${gid}, ${event.type}) took ${ms}ms`);
}
}

Expand Down

1 comment on commit e42fb88

@vercel
Copy link

@vercel vercel bot commented on e42fb88 Sep 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.