Load less stuff in memory for leaderboards

This commit is contained in:
Kalle
2022-03-26 17:34:07 +02:00
parent bb8c9dbafe
commit 63f5ba8ce7
2 changed files with 3 additions and 7 deletions

View File

@@ -1,16 +1,15 @@
import { Skill } from "@prisma/client";
import { AMOUNT_OF_ENTRIES_REQUIRED_FOR_LEADERBOARD } from "~/constants";
import { UserLean } from "~/utils";
import { muSigmaToSP } from "./utils";
export interface LeaderboardEntry {
MMR: number;
user: UserLean;
user: { id: string; discordName: string };
entries: number;
}
type SkillInput = Pick<Skill, "mu" | "sigma" | "userId"> & {
match: { createdAt: Date } | null;
user: UserLean;
user: { id: string; discordName: string };
};
type UserId = string;
@@ -35,9 +34,6 @@ export function skillsToLeaderboard(skills: SkillInput[]): LeaderboardEntry[] {
peakMMR[skill.userId] = {
MMR,
user: {
discordAvatar: skill.user.discordAvatar,
discordDiscriminator: skill.user.discordDiscriminator,
discordId: skill.user.discordId,
discordName: skill.user.discordName,
id: skill.user.id,
},

View File

@@ -25,7 +25,7 @@ export function findAllByMonth({
const to = new Date(Date.UTC(year, month, 0));
return db.skill.findMany({
include: { match: true, user: true },
include: { match: { select: { createdAt: true } }, user: true },
where: {
match: { AND: [{ createdAt: { gte: from } }, { createdAt: { lt: to } }] },
},