@@ -5,10 +5,10 @@ import FinishedMatchEntity from 'gameserver/model/finished-match.entity';
5
5
import { InjectRepository } from '@nestjs/typeorm' ;
6
6
import { MatchmakingMode } from 'gateway/shared-types/matchmaking-mode' ;
7
7
import PlayerInMatchEntity from 'gameserver/model/player-in-match.entity' ;
8
- import { ProcessRankedMatchCommand } from 'gameserver/command/ProcessRankedMatch/process-ranked-match.command' ;
9
8
import { CommandBus } from '@nestjs/cqrs' ;
10
- import { PlayerId } from 'gateway/shared-types/player-id' ;
11
9
import { MmrChangeLogEntity } from 'gameserver/model/mmr-change-log.entity' ;
10
+ import { Page } from 'rest/dto/page' ;
11
+ import { optimized } from 'util/optimized' ;
12
12
13
13
@Injectable ( )
14
14
export class MatchService {
@@ -27,8 +27,9 @@ export class MatchService {
27
27
private readonly mmrChangeLogEntityRepository : Repository < MmrChangeLogEntity > ,
28
28
) { }
29
29
30
- @measure ( "getMatchPage:fastest" )
31
- public async getMatchPageFastest (
30
+ @optimized ( true )
31
+ @measure ( "getMatchPage" )
32
+ public async getMatchPage (
32
33
page : number ,
33
34
perPage : number ,
34
35
mode ?: MatchmakingMode ,
@@ -73,8 +74,9 @@ export class MatchService {
73
74
74
75
// http_req_waiting...............: avg=218.18ms min=46.31ms med=176.7ms max=1.07s p(90)=348.67ms p(95)=641.38ms
75
76
// http_reqs......................: 1695 80.493324/s
76
- @measure ( "playerMatches:new" )
77
- public async playerMatchesNew (
77
+ @optimized ( true )
78
+ @measure ( "getPlayerMatches" )
79
+ public async getPlayerMatches (
78
80
steam_id : string ,
79
81
page : number ,
80
82
perPage : number ,
@@ -104,18 +106,56 @@ export class MatchService {
104
106
return Promise . combine ( [ pims , total ] ) ;
105
107
}
106
108
107
- async manuallyTriggerMmrForMatch ( matchId : number ) {
108
- // await this.mmrChangeLogEntityRepository.delete({ matchId : matchId });
109
109
110
- const m = await this . finishedMatchEntityRepository . findOne ( {
111
- where : { id : matchId } ,
110
+ @optimized ( true , 'Added index on pim.hero' )
111
+ @measure ( "heroMatches" )
112
+ public async heroMatches (
113
+ page : number ,
114
+ perPage : number ,
115
+ hero : string ,
116
+ ) : Promise < Page < FinishedMatchEntity > > {
117
+ const [ ids , count ] = await this . finishedMatchEntityRepository
118
+ . createQueryBuilder ( 'fm' )
119
+ . select ( [ 'fm.id' , 'fm.timestamp' ] )
120
+ . addOrderBy ( 'fm.timestamp' , 'DESC' )
121
+ . leftJoin ( 'fm.players' , 'pims' )
122
+ . where ( 'pims.hero = :hero' , { hero } )
123
+ . andWhere ( 'fm.matchmaking_mode in (:...modes)' , {
124
+ modes : [ MatchmakingMode . RANKED , MatchmakingMode . UNRANKED ] ,
125
+ } )
126
+ . take ( perPage )
127
+ . skip ( perPage * page )
128
+ . getManyAndCount ( ) ;
129
+
130
+ const mapped = await this . finishedMatchEntityRepository . find ( {
131
+ where : {
132
+ id : In ( ids . map ( t => t . id ) ) ,
133
+ } ,
112
134
} ) ;
113
- const winners = m . players
114
- . filter ( t => t . team === m . winner )
115
- . map ( it => new PlayerId ( it . playerId ) ) ;
116
- const losers = m . players
117
- . filter ( t => t . team !== m . winner )
118
- . map ( it => new PlayerId ( it . playerId ) ) ;
119
- await this . cbus . execute ( new ProcessRankedMatchCommand ( matchId , winners , losers , m . matchmaking_mode ) ) ;
135
+
136
+ return {
137
+ data : mapped ,
138
+ page ,
139
+ perPage : perPage ,
140
+ pages : Math . ceil ( count / perPage ) ,
141
+ } ;
120
142
}
143
+
144
+
145
+
146
+
147
+ // async manuallyTriggerMmrForMatch(matchId: number) {
148
+ // // await this.mmrChangeLogEntityRepository.delete({ matchId : matchId });
149
+ //
150
+ // const m = await this.finishedMatchEntityRepository.findOne({
151
+ // where: { id: matchId },
152
+ // });
153
+ // const winners = m.players
154
+ // .filter(t => t.team === m.winner)
155
+ // .map(it => new PlayerId(it.playerId));
156
+ // const losers = m.players
157
+ // .filter(t => t.team !== m.winner)
158
+ // .map(it => new PlayerId(it.playerId));
159
+ // await this.cbus.execute(new ProcessRankedMatchCommand(matchId, winners, losers, m.matchmaking_mode));
160
+ // }
121
161
}
0 commit comments