@@ -95,36 +95,34 @@ async function doRate() {
9595
9696async function prefetchGcData ( ) {
9797 while ( true ) {
98- // Find next row in the queue that doesn't have gcdata
9998 const { rows } = await db . raw < {
10099 rows : { match_seq_num : number ; match_id : number ; pgroup : PGroup } [ ] ;
101100 } > (
102- 'SELECT match_seq_num, match_id, pgroup from rating_queue WHERE gcdata IS NULL ORDER BY match_seq_num LIMIT 1 ' ,
101+ 'SELECT match_seq_num, match_id, pgroup from rating_queue WHERE gcdata IS NULL ORDER BY match_seq_num LIMIT 10 ' ,
103102 ) ;
104- const row = rows [ 0 ] ;
105- if ( ! row ) {
106- // No rows, wait and try again
107- await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
108- continue ;
109- }
110- // Attempt to fetch
111- const { data } = await gcFetcher . getOrFetchDataWithRetry ( row . match_id , {
112- pgroup : row . pgroup ,
113- } , 200 ) ;
114- if ( data ) {
115- // If successful, update
116- await db . raw (
117- 'UPDATE rating_queue SET gcdata = ? WHERE match_seq_num = ?' ,
118- [ JSON . stringify ( data ) , row . match_seq_num ] ,
119- ) ;
120- } else {
121- // Match can't be rated due to lack of data
122- await db . raw (
123- 'DELETE FROM rating_queue WHERE match_seq_num = ?' ,
124- row . match_seq_num ,
125- ) ;
126- redisCount ( 'rater_skip' ) ;
103+ if ( rows . length ) {
104+ // Attempt to fetch for each
105+ await Promise . all ( rows . map ( async ( row ) => {
106+ const { data } = await gcFetcher . getOrFetchDataWithRetry ( row . match_id , {
107+ pgroup : row . pgroup ,
108+ } , 500 ) ;
109+ if ( data ) {
110+ // If successful, update
111+ await db . raw (
112+ 'UPDATE rating_queue SET gcdata = ? WHERE match_seq_num = ?' ,
113+ [ JSON . stringify ( data ) , row . match_seq_num ] ,
114+ ) ;
115+ } else {
116+ // Match can't be rated due to lack of data
117+ await db . raw (
118+ 'DELETE FROM rating_queue WHERE match_seq_num = ?' ,
119+ row . match_seq_num ,
120+ ) ;
121+ redisCount ( 'rater_skip' ) ;
122+ }
123+ } ) ) ;
127124 }
125+ await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
128126 }
129127}
130128
0 commit comments