mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-03-21 18:04:39 -05:00
More fixing of plus server tier resolution (pass always correct seasonNth + for ongoing season use full tiers list)
This commit is contained in:
parent
e889edaa61
commit
a358606d4f
|
|
@ -563,7 +563,7 @@ async function lastMonthSuggestions() {
|
|||
|
||||
async function thisMonthsSuggestions() {
|
||||
const usersInPlus = (await UserRepository.findAllPlusServerMembers()).filter(
|
||||
(u) => u.id !== ADMIN_ID,
|
||||
(u) => u.userId !== ADMIN_ID,
|
||||
);
|
||||
const range = nextNonCompletedVoting(new Date());
|
||||
invariant(range, "No next voting found");
|
||||
|
|
@ -578,7 +578,7 @@ async function thisMonthsSuggestions() {
|
|||
invariant(suggester.plusTier);
|
||||
|
||||
await PlusSuggestionRepository.create({
|
||||
authorId: suggester.id,
|
||||
authorId: suggester.userId,
|
||||
month,
|
||||
year,
|
||||
suggestedId: userId,
|
||||
|
|
|
|||
|
|
@ -69,13 +69,18 @@ export function migrate(args: { newUserId: number; oldUserId: number }) {
|
|||
}
|
||||
|
||||
export function replacePlusTiers(
|
||||
plusTiers: Array<{ userId: number; tier: number }>,
|
||||
plusTiers: Array<{ userId: number; plusTier: number }>,
|
||||
) {
|
||||
invariant(plusTiers.length > 0, "plusTiers must not be empty");
|
||||
|
||||
return db.transaction().execute(async (trx) => {
|
||||
await trx.deleteFrom("PlusTier").execute();
|
||||
await trx.insertInto("PlusTier").values(plusTiers).execute();
|
||||
await trx
|
||||
.insertInto("PlusTier")
|
||||
.values(
|
||||
plusTiers.map(({ plusTier, userId }) => ({ userId, tier: plusTier })),
|
||||
)
|
||||
.execute();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ export async function plusTiersFromVotingAndLeaderboard() {
|
|||
}
|
||||
|
||||
function fromLeaderboard(
|
||||
newMembersFromVoting: Array<{ userId: number; tier: number }>,
|
||||
newMembersFromVoting: Array<{ userId: number; plusTier: number }>,
|
||||
) {
|
||||
const now = new Date();
|
||||
const lastCompletedSeason = previousSeason(now);
|
||||
|
|
@ -42,6 +42,7 @@ function fromLeaderboard(
|
|||
const leaderboard = addPendingPlusTiers(
|
||||
userSPLeaderboard(lastCompletedSeason.nth),
|
||||
newMembersFromVoting,
|
||||
lastCompletedSeason.nth,
|
||||
);
|
||||
|
||||
return leaderboard.flatMap((entry) => {
|
||||
|
|
@ -49,7 +50,7 @@ function fromLeaderboard(
|
|||
|
||||
return {
|
||||
userId: entry.id,
|
||||
tier: entry.pendingPlusTier,
|
||||
plusTier: entry.pendingPlusTier,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ import { cachified } from "@epic-web/cachified";
|
|||
import { HALF_HOUR_IN_MS } from "~/constants";
|
||||
import { USER_LEADERBOARD_MIN_ENTRIES_FOR_LEVIATHAN } from "~/features/mmr/mmr-constants";
|
||||
import { spToOrdinal } from "~/features/mmr/mmr-utils";
|
||||
import { currentOrPreviousSeason, currentSeason } from "~/features/mmr/season";
|
||||
import { currentSeason } from "~/features/mmr/season";
|
||||
import { freshUserSkills, userSkills } from "~/features/mmr/tiered.server";
|
||||
import * as PlusVotingRepository from "~/features/plus-voting/PlusVotingRepository.server";
|
||||
import * as UserRepository from "~/features/user-page/UserRepository.server";
|
||||
import type { MainWeaponId } from "~/modules/in-game-lists";
|
||||
import { weaponCategories } from "~/modules/in-game-lists";
|
||||
import { cache, ttl } from "~/utils/cache.server";
|
||||
|
|
@ -34,7 +34,8 @@ export async function cachedFullUserLeaderboard(season: number) {
|
|||
const withPendingPlusTiers = shouldAddPendingPlusTier
|
||||
? addPendingPlusTiers(
|
||||
withTiers,
|
||||
await PlusVotingRepository.allPlusTiersFromLatestVoting(),
|
||||
await UserRepository.findAllPlusServerMembers(),
|
||||
season,
|
||||
)
|
||||
: withTiers;
|
||||
|
||||
|
|
@ -76,8 +77,9 @@ export function addPendingPlusTiers<T extends UserSPLeaderboardItem>(
|
|||
entries: T[],
|
||||
plusTiers: Array<{
|
||||
userId: number;
|
||||
tier: number;
|
||||
plusTier: number;
|
||||
}>,
|
||||
seasonNth: number,
|
||||
) {
|
||||
const quota: { "+1": number; "+2": number; "+3": number } = {
|
||||
...PLUS_TIER_QUOTA,
|
||||
|
|
@ -95,12 +97,10 @@ export function addPendingPlusTiers<T extends UserSPLeaderboardItem>(
|
|||
const highestPlusTierWithSpace = resolveHighestPlusTierWithSpace();
|
||||
if (!highestPlusTierWithSpace) break;
|
||||
|
||||
const plusTier = plusTiers.find((t) => t.userId === entry.id)?.tier;
|
||||
const plusTier = plusTiers.find((t) => t.userId === entry.id)?.plusTier;
|
||||
|
||||
if (plusTier && plusTier <= highestPlusTierWithSpace) continue;
|
||||
if (
|
||||
entry.plusSkippedForSeasonNth === currentOrPreviousSeason(new Date())?.nth
|
||||
) {
|
||||
if (entry.plusSkippedForSeasonNth === seasonNth) {
|
||||
entry.plusSkippedForSeasonNth = null;
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,9 +33,9 @@ type ResultsByMonthYearQueryReturnType = InferResult<
|
|||
export function allPlusTiersFromLatestVoting() {
|
||||
return db
|
||||
.selectFrom("FreshPlusTier")
|
||||
.select(["FreshPlusTier.userId", "FreshPlusTier.tier"])
|
||||
.select(["FreshPlusTier.userId", "FreshPlusTier.tier as plusTier"])
|
||||
.where("FreshPlusTier.tier", "is not", null)
|
||||
.execute() as Promise<{ userId: number; tier: number }[]>;
|
||||
.execute() as Promise<{ userId: number; plusTier: number }[]>;
|
||||
}
|
||||
|
||||
export type ResultsByMonthYearItem = Unwrapped<typeof resultsByMonthYear>;
|
||||
|
|
|
|||
|
|
@ -308,7 +308,11 @@ export function findAllPlusServerMembers() {
|
|||
return db
|
||||
.selectFrom("User")
|
||||
.innerJoin("PlusTier", "PlusTier.userId", "User.id")
|
||||
.select(["User.id", "User.discordId", "PlusTier.tier as plusTier"])
|
||||
.select([
|
||||
"User.id as userId",
|
||||
"User.discordId",
|
||||
"PlusTier.tier as plusTier",
|
||||
])
|
||||
.execute();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ export const NotifyPlusServerVotingRoutine = new Routine({
|
|||
},
|
||||
},
|
||||
userIds: (await UserRepository.findAllPlusServerMembers()).map(
|
||||
(member) => member.id,
|
||||
(member) => member.userId,
|
||||
),
|
||||
});
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user