mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-10-02 16:20:36 -05:00
Migrate addInitialSkill to Kysely
This commit is contained in:
@@ -1,7 +1,38 @@
|
||||
import { sql } from "kysely";
|
||||
import { sql, type Transaction } from "kysely";
|
||||
import { ordinal } from "openskill";
|
||||
import { db } from "~/db/sql";
|
||||
import type { DB } from "~/db/tables";
|
||||
import { MATCHES_COUNT_NEEDED_FOR_LEADERBOARD } from "../leaderboards/leaderboards-constants";
|
||||
|
||||
export async function addInitialSkill(
|
||||
{
|
||||
mu,
|
||||
sigma,
|
||||
season,
|
||||
userId,
|
||||
}: {
|
||||
mu: number;
|
||||
sigma: number;
|
||||
season: number;
|
||||
userId: number;
|
||||
},
|
||||
trx?: Transaction<DB>,
|
||||
) {
|
||||
const executor = trx ?? db;
|
||||
|
||||
await executor
|
||||
.insertInto("Skill")
|
||||
.values({
|
||||
mu,
|
||||
sigma,
|
||||
season,
|
||||
ordinal: ordinal({ mu, sigma }),
|
||||
userId,
|
||||
matchesCount: 0,
|
||||
})
|
||||
.execute();
|
||||
}
|
||||
|
||||
export async function seasonProgressionByUserId({
|
||||
userId,
|
||||
season,
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
import { ordinal } from "openskill";
|
||||
import { sql } from "~/db/sql";
|
||||
|
||||
const stm = sql.prepare(/* sql */ `
|
||||
insert into "Skill" ("mu", "season", "sigma", "ordinal", "userId", "matchesCount")
|
||||
values (
|
||||
@mu,
|
||||
@season,
|
||||
@sigma,
|
||||
@ordinal,
|
||||
@userId,
|
||||
0
|
||||
)
|
||||
`);
|
||||
|
||||
export function addInitialSkill({
|
||||
mu,
|
||||
sigma,
|
||||
season,
|
||||
userId,
|
||||
}: {
|
||||
mu: number;
|
||||
sigma: number;
|
||||
season: number;
|
||||
userId: number;
|
||||
}) {
|
||||
stm.run({
|
||||
mu,
|
||||
sigma,
|
||||
season,
|
||||
ordinal: ordinal({ mu, sigma }),
|
||||
userId,
|
||||
});
|
||||
}
|
||||
@@ -3,8 +3,8 @@ import { ordinal } from "openskill";
|
||||
import { db, sql } from "~/db/sql";
|
||||
import type { Tables } from "~/db/tables";
|
||||
import { TIERS, type TierName } from "~/features/mmr/mmr-constants";
|
||||
import * as SkillRepository from "~/features/mmr/SkillRepository.server";
|
||||
import { freshUserSkills } from "~/features/mmr/tiered.server";
|
||||
import { addInitialSkill } from "~/features/sendouq/queries/addInitialSkill.server";
|
||||
import invariant from "~/utils/invariant";
|
||||
import { logger } from "~/utils/logger";
|
||||
|
||||
@@ -174,18 +174,12 @@ const newSkills = allSkills.map((s) => {
|
||||
};
|
||||
});
|
||||
|
||||
const allGroupsInactiveStm = sql.prepare(/* sql */ `
|
||||
update
|
||||
"Group"
|
||||
set
|
||||
"status" = 'INACTIVE'
|
||||
`);
|
||||
sql.transaction(() => {
|
||||
await db.transaction().execute(async (trx) => {
|
||||
for (const skill of newSkills) {
|
||||
addInitialSkill(skill);
|
||||
await SkillRepository.addInitialSkill(skill, trx);
|
||||
}
|
||||
allGroupsInactiveStm.run();
|
||||
})();
|
||||
await trx.updateTable("Group").set({ status: "INACTIVE" }).execute();
|
||||
});
|
||||
|
||||
logger.info(
|
||||
`Done adding new skills for season ${nth} (${newSkills.length} added)`,
|
||||
|
||||
Reference in New Issue
Block a user