Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ playground/*

# Search index
search-index.json

# TypeScript incremental build info
*.tsbuildinfo
42 changes: 39 additions & 3 deletions apps/frontend/app/all/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { PlayerList } from '../../components/PlayerList';
import { getGlobalCounts } from '@teerank/teerank';
import {
getGlobalCounts,
STUB_MIN_POLL_COUNT,
STUB_OCCURRENCE_RATIO,
} from '@teerank/teerank';
import {
countPlayersWithoutShared,
listPlayersWithoutShared,
} from '@prisma/client/sql';
import prisma from '../../utils/prisma';
import { searchParamSchema } from './schema';
import redis from '../../utils/redis';
import { sharedHiddenParam } from '../../utils/shared';

export const metadata = {
title: 'All Players - Teerank',
Expand All @@ -19,12 +28,37 @@ export default async function Index({
}) {
const { page } = searchParamSchema.parse(searchParams);

let nameFilter: string[] | undefined;
let filteredCount: number | undefined;

if (sharedHiddenParam(searchParams)) {
const [names, counts] = await Promise.all([
prisma.$queryRawTyped(
listPlayersWithoutShared(
STUB_MIN_POLL_COUNT,
STUB_OCCURRENCE_RATIO,
100,
(page - 1) * 100
)
),
prisma.$queryRawTyped(
countPlayersWithoutShared(STUB_MIN_POLL_COUNT, STUB_OCCURRENCE_RATIO)
),
]);

nameFilter = names.map((row) => row.name);
filteredCount = Number(counts[0]?.count ?? 0);
}

const players = await prisma.player.findMany({
where: nameFilter === undefined ? undefined : { name: { in: nameFilter } },
select: {
name: true,
playTime: true,
clanName: true,
lastSeenAt: true,
pollCount: true,
occurrenceCount: true,

gameServerStateClients: {
select: {
Expand All @@ -45,7 +79,7 @@ export default async function Index({
playTime: 'desc',
},
take: 100,
skip: (page - 1) * 100,
skip: nameFilter === undefined ? (page - 1) * 100 : 0,
});

const globalCounts = await getGlobalCounts(redis);
Expand All @@ -56,7 +90,7 @@ export default async function Index({
{`Teerank is a simple and fast ranking system for Teeworlds.`}
</p>
<PlayerList
playerCount={globalCounts.players}
playerCount={filteredCount ?? globalCounts.players}
rankMethod={null}
showLastSeen={true}
players={players.map((player, index) => ({
Expand All @@ -66,6 +100,8 @@ export default async function Index({
rating: undefined,
playTime: player.playTime,
lastSeenAt: player.lastSeenAt,
pollCount: player.pollCount,
occurrenceCount: player.occurrenceCount,
gameServers: player.gameServerStateClients.map((client) => ({
ip: client.gameServerState.gameServer?.ip ?? '',
port: client.gameServerState.gameServer?.port ?? 0,
Expand Down
32 changes: 0 additions & 32 deletions apps/frontend/app/clan/[clanName]/PastMembersToggle.tsx

This file was deleted.

60 changes: 50 additions & 10 deletions apps/frontend/app/clan/[clanName]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import { PlayerList } from '../../../components/PlayerList';
import { searchParamPageSchema } from '../../../utils/page';
import { Metadata } from 'next';
import { encodeString } from '../../../utils/encoding';
import Link from 'next/link';
import { PastMembersToggle } from './PastMembersToggle';
import { STUB_MIN_POLL_COUNT, STUB_OCCURRENCE_RATIO } from '@teerank/teerank';
import {
countClanPlayersWithoutShared,
listClanPlayersWithoutShared,
} from '@prisma/client/sql';
import { sharedHiddenParam } from '../../../utils/shared';
export async function generateMetadata({
params,
}: {
Expand Down Expand Up @@ -35,6 +39,35 @@ export default async function Index({
const { page } = searchParamPageSchema.parse(searchParams);
const showPastMembers = searchParams.past === 'true' || searchParams.past === '1';

let nameFilter: string[] | undefined;
let filteredCount: number | undefined;

if (sharedHiddenParam(searchParams)) {
const [names, counts] = await Promise.all([
prisma.$queryRawTyped(
listClanPlayersWithoutShared(
clanName,
showPastMembers,
STUB_MIN_POLL_COUNT,
STUB_OCCURRENCE_RATIO,
100,
(page - 1) * 100
)
),
prisma.$queryRawTyped(
countClanPlayersWithoutShared(
clanName,
showPastMembers,
STUB_MIN_POLL_COUNT,
STUB_OCCURRENCE_RATIO
)
),
]);

nameFilter = names.map((row) => row.playerName);
filteredCount = Number(counts[0]?.count ?? 0);
}

const clan = await prisma.clan.findUnique({
select: {
activePlayerCount: true,
Expand All @@ -51,6 +84,8 @@ export default async function Index({
name: true,
clanName: true,
lastSeenAt: true,
pollCount: true,
occurrenceCount: true,
gameServerStateClients: {
select: {
gameServerState: {
Expand All @@ -69,16 +104,17 @@ export default async function Index({
},
},
},
where: showPastMembers ? undefined : {
player: {
clanName,
},
},
where:
nameFilter === undefined
? showPastMembers
? undefined
: { player: { clanName } }
: { playerName: { in: nameFilter } },
orderBy: {
playTime: 'desc',
},
take: 100,
skip: (page - 1) * 100,
skip: nameFilter === undefined ? (page - 1) * 100 : 0,
},
},
where: {
Expand All @@ -90,7 +126,9 @@ export default async function Index({
return notFound();
}

const playerCount = showPastMembers ? clan._count.clanPlayerInfos : clan.activePlayerCount;
const playerCount =
filteredCount ??
(showPastMembers ? clan._count.clanPlayerInfos : clan.activePlayerCount);
const maxPage = Math.ceil(playerCount / 100) || 1;

if (page > maxPage) {
Expand All @@ -111,18 +149,20 @@ export default async function Index({

return (
<div className="flex flex-col gap-4">
<PastMembersToggle clanName={clanName} showPastMembers={showPastMembers} />
<PlayerList
playerCount={playerCount}
rankMethod={null}
showLastSeen={true}
showInactiveToggle={true}
players={clan.clanPlayerInfos.map((playerInfo, index) => ({
rank: index + 1,
name: playerInfo.player.name,
clan: clanName,
isActiveClan: playerInfo.player.clanName === clanName,
playTime: playerInfo.playTime,
lastSeenAt: playerInfo.player.lastSeenAt,
pollCount: playerInfo.player.pollCount,
occurrenceCount: playerInfo.player.occurrenceCount,
gameServers: playerInfo.player.gameServerStateClients.map((client) => ({
ip: client.gameServerState.gameServer?.ip ?? '',
port: client.gameServerState.gameServer?.port ?? 0,
Expand Down
45 changes: 43 additions & 2 deletions apps/frontend/app/gametype/[gameTypeName]/(lists)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import { notFound } from 'next/navigation';
import { encodeString } from '../../../../utils/encoding';
import { Metadata } from 'next';
import { z } from 'zod';
import { STUB_MIN_POLL_COUNT, STUB_OCCURRENCE_RATIO } from '@teerank/teerank';
import {
countGameTypePlayersWithoutShared,
listGameTypePlayersWithoutShared,
} from '@prisma/client/sql';
import { sharedHiddenParam } from '../../../../utils/shared';

export async function generateMetadata({
params,
Expand Down Expand Up @@ -33,11 +39,42 @@ export default async function Index({
const { page } = searchParamsSchema.parse(searchParams);
const { gameTypeName } = paramsSchema.parse(params);

let nameFilter: string[] | undefined;
let filteredCount: number | undefined;

if (sharedHiddenParam(searchParams)) {
const [names, counts] = await Promise.all([
prisma.$queryRawTyped(
listGameTypePlayersWithoutShared(
gameTypeName,
STUB_MIN_POLL_COUNT,
STUB_OCCURRENCE_RATIO,
100,
(page - 1) * 100
)
),
prisma.$queryRawTyped(
countGameTypePlayersWithoutShared(
gameTypeName,
STUB_MIN_POLL_COUNT,
STUB_OCCURRENCE_RATIO
)
),
]);

nameFilter = names.map((row) => row.playerName);
filteredCount = Number(counts[0]?.count ?? 0);
}

const gameType = await prisma.gameType.findUnique({
select: {
rankMethod: true,
playerCount: true,
playerInfoGameTypes: {
where:
nameFilter === undefined
? undefined
: { playerName: { in: nameFilter } },
select: {
rating: true,
playTime: true,
Expand All @@ -46,6 +83,8 @@ export default async function Index({
select: {
clanName: true,
lastSeenAt: true,
pollCount: true,
occurrenceCount: true,
gameServerStateClients: {
select: {
gameServerState: {
Expand All @@ -70,7 +109,7 @@ export default async function Index({
},
],
take: 100,
skip: (page - 1) * 100,
skip: nameFilter === undefined ? (page - 1) * 100 : 0,
},
},
where: {
Expand All @@ -84,7 +123,7 @@ export default async function Index({

return (
<PlayerList
playerCount={gameType.playerCount}
playerCount={filteredCount ?? gameType.playerCount}
rankMethod={gameType.rankMethod === RankMethod.TIME ? null : gameType.rankMethod}
players={gameType.playerInfoGameTypes.map((playerInfoGameType, index) => ({
rank: (page - 1) * 100 + index + 1,
Expand All @@ -93,6 +132,8 @@ export default async function Index({
rating: playerInfoGameType.rating ?? undefined,
playTime: playerInfoGameType.playTime,
lastSeenAt: playerInfoGameType.player.lastSeenAt,
pollCount: playerInfoGameType.player.pollCount,
occurrenceCount: playerInfoGameType.player.occurrenceCount,
gameServers: playerInfoGameType.player.gameServerStateClients.map((client) => ({
ip: client.gameServerState.gameServer?.ip ?? '',
port: client.gameServerState.gameServer?.port ?? 0,
Expand Down
Loading
Loading