Make sure the poyashi script recalcs iidx profiles.

This commit is contained in:
zkldi
2021-11-30 16:57:28 +00:00
parent 5cdd7cc63f
commit 2ccd06cf8d
2 changed files with 40 additions and 0 deletions
@@ -0,0 +1,37 @@
/* eslint-disable no-await-in-loop */
import db from "external/mongo/db";
import CreateLogCtx from "lib/logger/logger";
import { CreateSessionCalcData } from "lib/score-import/framework/sessions/calculated-data";
import { UpdateUsersGamePlaytypeStats } from "lib/score-import/framework/user-game-stats/update-ugs";
import { FormatUserDoc } from "utils/user";
const logger = CreateLogCtx(__filename);
export async function RecalcGameProfiles(filter = {}) {
const profiles = await db["game-stats"].find(filter);
for (const profile of profiles) {
const user = await db.users.findOne({
id: profile.userID,
});
if (!user) {
logger.severe(`User ${profile.userID} does not exist?`);
throw new Error(`User ${profile.userID} does not exist.`);
}
logger.verbose(
`Recalcing ${FormatUserDoc(user)}'s ${profile.game} ${profile.playtype} stats.`
);
await UpdateUsersGamePlaytypeStats(
profile.game,
profile.playtype,
profile.userID,
null,
logger
);
}
logger.info(`Done.`);
}