perf upgrade

This commit is contained in:
yohlo
2026-07-12 21:26:16 -07:00
parent ec334bbed4
commit 778f0f7994
74 changed files with 1522 additions and 1014 deletions
+20 -13
View File
@@ -34,10 +34,19 @@ export function createTeamsService(pb: PocketBase) {
logger.info("PocketBase | Creating team", data);
try {
for (const playerId of data.players) {
const playerExists = await pb.collection("players").getOne(playerId).catch(() => null);
if (!playerExists) {
throw new Error(`Player with ID ${playerId} not found`);
if (data.players.length > 0) {
const playerFilter = data.players
.map((playerId) => `id = "${playerId}"`)
.join(" || ");
const existingPlayers = await pb.collection("players").getFullList({
filter: playerFilter,
fields: "id",
});
if (existingPlayers.length !== data.players.length) {
const foundIds = new Set(existingPlayers.map((player) => player.id));
const missingId = data.players.find((playerId) => !foundIds.has(playerId));
throw new Error(`Player with ID ${missingId} not found`);
}
}
@@ -46,11 +55,13 @@ export function createTeamsService(pb: PocketBase) {
players: data.players
});
for (const playerId of data.players) {
await pb.collection("players").update(playerId, {
"teams+": result.id
});
}
await Promise.all(
data.players.map((playerId) =>
pb.collection("players").update(playerId, {
"teams+": result.id
})
)
);
return transformTeam(await pb.collection("teams").getOne(result.id, {
expand: "players, tournaments"
@@ -72,10 +83,6 @@ export function createTeamsService(pb: PocketBase) {
const result = await pb.collection("teams").update(id, data);
if (data instanceof FormData && data.has('logo')) {
await new Promise(resolve => setTimeout(resolve, 100));
}
const updated = await pb.collection("teams").getOne(result.id, {
expand: "players, tournaments",
// @ts-ignore - Add cache busting