Skip to content

Commit 413b784

Browse files
committed
Make it fast and good
1 parent 72ed83d commit 413b784

File tree

2 files changed

+43
-30
lines changed

2 files changed

+43
-30
lines changed

src/rest/player.controller.ts

+34-30
Original file line numberDiff line numberDiff line change
@@ -187,37 +187,41 @@ offset $2 limit $3`,
187187
where: { steam_id },
188188
});
189189

190+
191+
// Crucial thing for newbie:
192+
const hasUnrankedAccess = await this.playerService.hasUnrankedAccess(steam_id)
193+
190194
// if it exists in the view, we happy
191-
// if (lb) {
192-
// return {
193-
// rank: lb.rank,
194-
//
195-
// steam_id: lb.steam_id,
196-
// mmr: lb.mmr,
197-
//
198-
// games: lb.games,
199-
// wins: lb.wins,
200-
//
201-
// kills: lb.kills,
202-
// deaths: lb.deaths,
203-
// assists: lb.assists,
204-
//
205-
// play_time: lb.play_time,
206-
// playedAnyGame: lb.any_games > 0,
207-
//
208-
// hasUnrankedAccess: lb.bot_wins > 0,
209-
//
210-
// newbieUnrankedGamesLeft:
211-
// lb.ranked_games > 0
212-
// ? 0
213-
// : Math.max(0, UNRANKED_GAMES_REQUIRED_FOR_RANKED - lb.games),
214-
//
215-
// calibrationGamesLeft: Math.max(
216-
// ProcessRankedMatchHandler.TOTAL_CALIBRATION_GAMES - lb.ranked_games,
217-
// 0,
218-
// ),
219-
// };
220-
// }
195+
if (lb) {
196+
return {
197+
rank: lb.rank,
198+
199+
steam_id: lb.steam_id,
200+
mmr: lb.mmr,
201+
202+
games: lb.games,
203+
wins: lb.wins,
204+
205+
kills: lb.kills,
206+
deaths: lb.deaths,
207+
assists: lb.assists,
208+
209+
play_time: lb.play_time,
210+
playedAnyGame: lb.any_games > 0,
211+
212+
hasUnrankedAccess: hasUnrankedAccess,
213+
214+
newbieUnrankedGamesLeft:
215+
lb.ranked_games > 0
216+
? 0
217+
: Math.max(0, UNRANKED_GAMES_REQUIRED_FOR_RANKED - lb.games),
218+
219+
calibrationGamesLeft: Math.max(
220+
ProcessRankedMatchHandler.TOTAL_CALIBRATION_GAMES - lb.ranked_games,
221+
0,
222+
),
223+
};
224+
}
221225

222226
const summary: Summary | undefined =
223227
await this.playerService.fullSummary(steam_id);

src/rest/service/player.service.ts

+9
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,13 @@ group by p.steam_id, p.recent_ranked_games, p.mmr, p.games, p.wins, p.any_games,
192192

193193
return some[0];
194194
}
195+
196+
public async hasUnrankedAccess(steam_id: string): Promise<boolean> {
197+
const result: { count: number }[] =
198+
await this.playerInMatchRepository.query(
199+
`select count(*) from player_activity pa where pa.win and pa.steam_id = $1`,
200+
[steam_id],
201+
);
202+
return result[0].count > 0;
203+
}
195204
}

0 commit comments

Comments
 (0)