11import config from '../config' ;
2- import { blobArchive , matchArchive , playerArchive } from '../store/archive' ;
3- import cassandra from '../store/cassandra' ;
2+ import { matchArchive , playerArchive } from '../store/archive' ;
43import QueryStream from 'pg-query-stream' ;
54import { Client } from 'pg' ;
6- import crypto from 'crypto' ;
75import db from '../store/db' ;
8- import { apiFetcher } from '../fetcher/getApiData' ;
9- import { gcFetcher } from '../fetcher/getGcData' ;
10- import { parsedFetcher } from '../fetcher/getParsedData' ;
116import type { PutObjectCommandOutput } from '@aws-sdk/client-s3' ;
127import { getFullPlayerMatchesWithMetadata } from './buildPlayer' ;
138import { getMatchDataFromBlobWithMetadata } from './buildMatch' ;
@@ -25,48 +20,6 @@ async function processMatch(matchId: number) {
2520 // }
2621 // await doArchiveMatchFromBlobs(matchId);
2722 // }
28- await doMigrateMatchToBlobStore ( matchId ) ;
29- }
30-
31- /**
32- * Moves individual match blobs from Cassandra to blob store
33- * @param matchId
34- * @returns
35- */
36- async function doMigrateMatchToBlobStore ( matchId : number ) {
37- const api = await apiFetcher . readData ( matchId , true ) ;
38- const gcdata = await gcFetcher . readData ( matchId , true ) ;
39- const parsed = await parsedFetcher . readData ( matchId , true ) ;
40- if ( api ) {
41- // If the match is old we might not be able to get back ability builds, HD/TD/HH from Steam so we want to keep the API data
42- await blobArchive . archivePut (
43- matchId . toString ( ) + '_api' ,
44- Buffer . from ( JSON . stringify ( api ) ) ,
45- ) ;
46- }
47- if ( gcdata ) {
48- await blobArchive . archivePut (
49- matchId . toString ( ) + '_gcdata' ,
50- Buffer . from ( JSON . stringify ( gcdata ) ) ,
51- ) ;
52- }
53- if ( parsed ) {
54- await blobArchive . archivePut (
55- matchId . toString ( ) + '_parsed' ,
56- Buffer . from ( JSON . stringify ( parsed ) ) ,
57- ) ;
58- }
59- await deleteMatch ( matchId ) ;
60- }
61-
62- async function deleteMatch ( matchId : number ) {
63- await cassandra . execute (
64- 'DELETE from match_blobs WHERE match_id = ?' ,
65- [ matchId ] ,
66- {
67- prepare : true ,
68- } ,
69- ) ;
7023}
7124
7225export async function archivePostgresStream ( ) {
@@ -123,16 +76,6 @@ async function archiveRandom(max: number) {
12376 await Promise . allSettled ( page . map ( ( i ) => processMatch ( i ) ) ) ;
12477}
12578
126- export async function archiveToken ( max ?: number ) {
127- // Archive random matches from Cassandra using token range (not all may be parsed)
128- let page = await getTokenRange ( 10 ) ;
129- if ( max ) {
130- page = page . filter ( ( id ) => id < max ) ;
131- }
132- console . log ( page [ 0 ] ) ;
133- await Promise . allSettled ( page . map ( ( i ) => processMatch ( i ) ) ) ;
134- }
135-
13679function randomInt ( min : number , max : number ) {
13780 return Math . floor ( Math . random ( ) * ( max - min ) + min ) ;
13881}
@@ -144,19 +87,6 @@ export async function getCurrentMaxArchiveID() {
14487 return limit ;
14588}
14689
147- async function getTokenRange ( size : number ) {
148- const result = await cassandra . execute (
149- 'select match_id, token(match_id) from match_blobs limit ? ALLOW FILTERING;' ,
150- [ size ] ,
151- {
152- prepare : true ,
153- fetchSize : size ,
154- autoPage : true ,
155- } ,
156- ) ;
157- return result . rows . map ( ( row ) => Number ( row . match_id ) ) ;
158- }
159-
16090async function doArchivePlayerMatches (
16191 accountId : number ,
16292) : Promise < PutObjectCommandOutput | null > {
@@ -200,8 +130,6 @@ export async function doArchiveMatchFromBlobs(matchId: number) {
200130 // Don't read from archive when determining whether to archive
201131 const [ match , metadata ] = await getMatchDataFromBlobWithMetadata ( matchId , {
202132 noArchive : true ,
203- // TODO Remove noBlobStore once migrated
204- noBlobStore : true ,
205133 } ) ;
206134 if ( match && metadata ?. has_parsed ) {
207135 // check data completeness with isDataComplete
0 commit comments