diff --git a/TODO.txt b/TODO.txt index 06d2806af..fcbb1be99 100644 --- a/TODO.txt +++ b/TODO.txt @@ -229,7 +229,7 @@ * alert on unit captured or destroyed 12/20/2024 * only check islands/clusters when being attacked DONE 12/10/2024 * only calculate name if tile changes DONE 12/10/2024 -* store in BigQuery +* store in BigQuery DONE 12/10/2024 * allow longer names and allow them to be displayed in the Rank UI not be cut * make boats work on lakes (& oceania) * record game winner diff --git a/src/client/LocalServer.ts b/src/client/LocalServer.ts index 28562adfb..5c4f4a902 100644 --- a/src/client/LocalServer.ts +++ b/src/client/LocalServer.ts @@ -53,6 +53,8 @@ export class LocalServer { console.log('local server ending game') clearInterval(this.endTurnIntervalID) const record = CreateGameRecord(this.gameID, this.gameConfig, this.turns, this.startedAt, Date.now()) + // Clear turns because beacon only supports up to 64kb + record.turns = [] // For unload events, sendBeacon is the only reliable method const blob = new Blob([JSON.stringify(GameRecordSchema.parse(record))], { type: 'application/json' diff --git a/src/server/Archive.ts b/src/server/Archive.ts index c8cfe615b..f30a52d80 100644 --- a/src/server/Archive.ts +++ b/src/server/Archive.ts @@ -8,12 +8,6 @@ const bigquery = new BigQuery(); export async function archive(gameRecord: GameRecord) { try { - console.log(`writing game ${gameRecord.id} to gcs`) - const bucket = storage.bucket("openfront-games"); - const file = bucket.file(gameRecord.id); - await file.save(JSON.stringify(GameRecordSchema.parse(gameRecord)), { - contentType: 'application/json' - }); // Save metadata to BigQuery const row = { id: gameRecord.id, @@ -34,7 +28,15 @@ export async function archive(gameRecord: GameRecord) { .insert([row]); console.log(`wrote game metadata to BigQuery: ${gameRecord.id}`); + if (gameRecord.turns.length > 0) { + console.log(`writing game ${gameRecord.id} to gcs`) + const bucket = storage.bucket("openfront-games"); + const file = bucket.file(gameRecord.id); + await file.save(JSON.stringify(GameRecordSchema.parse(gameRecord)), { + contentType: 'application/json' + }); + } } catch (error) { - console.log(`error writing to gcs: ${error}`) + console.log(`error archiving game record: ${error}`) } } \ No newline at end of file