This commit is contained in:
@@ -79,23 +79,33 @@ export function migrateModeration(handle: Database.Database): void {
|
||||
const alias = handle.prepare(`INSERT INTO moderation_aliases VALUES(?,?,?,?,?)
|
||||
ON CONFLICT(game,guid,name) DO UPDATE SET
|
||||
first_seen_at=MIN(first_seen_at,excluded.first_seen_at),last_seen_at=MAX(last_seen_at,excluded.last_seen_at)`);
|
||||
for (const row of handle
|
||||
.prepare("SELECT * FROM leaderboard_players WHERE game IN ('t5','t6')")
|
||||
.iterate() as Iterable<{
|
||||
type Player = {
|
||||
game: ModerationGame;
|
||||
guid: string;
|
||||
name: string;
|
||||
first_seen_at: string;
|
||||
last_seen_at: string;
|
||||
}>) {
|
||||
const values = [
|
||||
row.game,
|
||||
moderationGuid(row.game, row.guid),
|
||||
row.name,
|
||||
row.first_seen_at,
|
||||
row.last_seen_at
|
||||
];
|
||||
player.run(...values);
|
||||
alias.run(...values);
|
||||
};
|
||||
const read = handle.prepare(`SELECT * FROM leaderboard_players
|
||||
WHERE game IN ('t5','t6') AND (game,guid)>(?,?) ORDER BY game,guid LIMIT 1000`);
|
||||
let cursor = ['', ''];
|
||||
for (;;) {
|
||||
// Finish each read before writing on this connection, without loading
|
||||
// the full historical player directory into memory during an upgrade.
|
||||
const rows = read.all(...cursor) as Player[];
|
||||
if (!rows.length) break;
|
||||
for (const row of rows) {
|
||||
const values = [
|
||||
row.game,
|
||||
moderationGuid(row.game, row.guid),
|
||||
row.name,
|
||||
row.first_seen_at,
|
||||
row.last_seen_at
|
||||
];
|
||||
player.run(...values);
|
||||
alias.run(...values);
|
||||
}
|
||||
const last = rows[rows.length - 1];
|
||||
cursor = [last.game, last.guid];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user