-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable hints on Set-Chain and UltraSet (#178)
This enables hints on all game types. I actually don't remember why this wasn't enabled from the start. Anyway because this will disrupt about 20,000 games played in the profile pages that have enableHint set to `true` but were in set-chain/ultraset, I also wrote a migration script to fix this.
- Loading branch information
Showing
5 changed files
with
64 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,44 @@ | ||
// Note: This is deprecated. | ||
import assert from "assert"; | ||
import { getDatabase } from "firebase-admin/database"; | ||
import PQueue from "p-queue"; | ||
|
||
/** Fix games that have `endedAt === 0` due to a site migration bug in v3.0.0. */ | ||
import { databaseIterator } from "./utils.js"; | ||
|
||
/** | ||
* Fix games that have `enableHint` in game modes that did not support hints. | ||
* | ||
* This is a retroactive migration script for version 3.5.0, where we're | ||
* enabling hints for all game modes and therefore need a way to track in the | ||
* database which games actually had hints on. | ||
* | ||
* About 0.2% of historical games needed to be updated. | ||
*/ | ||
export async function fixGames() { | ||
const badGames = await getDatabase() | ||
.ref("games") | ||
.orderByChild("endedAt") | ||
.equalTo(0) | ||
.once("value"); | ||
let count = 0; | ||
const queue = new PQueue({ concurrency: 200 }); | ||
|
||
for (const [gameId, game] of Object.entries(badGames.val())) { | ||
console.log(`Fixing game ${gameId}...`); | ||
console.log({ [gameId]: game }); | ||
assert.strictEqual(game.status, "done"); | ||
const events = await getDatabase() | ||
.ref(`gameData/${gameId}/events`) | ||
.once("value"); | ||
let lastTime = 0; | ||
events.forEach((event) => { | ||
lastTime = event.val().time; | ||
}); | ||
console.log(`Setting endedAt = ${lastTime}...`); | ||
await getDatabase().ref(`games/${gameId}/endedAt`).set(lastTime); | ||
console.log("Done.\n"); | ||
for await (const [gameId, game] of databaseIterator("games")) { | ||
if (++count % 100000 === 0) { | ||
console.log(`Processed ${count} games...`); | ||
} | ||
const { enableHint, users, access, mode } = game.val(); | ||
// See hasHint() function in util.js | ||
if ( | ||
enableHint && | ||
users && | ||
Object.keys(users).length === 1 && | ||
access === "private" && | ||
(mode === "setchain" || mode === "ultraset") | ||
) { | ||
console.log(`Fixing game ${gameId}...`); | ||
// Change this to `true` when you're ready to do a non-dry run. | ||
// eslint-disable-next-line no-constant-condition | ||
if (false) { | ||
await queue.onEmpty(); | ||
queue.add(getDatabase().ref(`games/${gameId}/enableHint`).set(false)); | ||
} | ||
} | ||
} | ||
|
||
await queue.onIdle(); | ||
console.log("Completed all games!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters