Skip to content

Commit

Permalink
Use activePlayerCount in all ClanList queries
Browse files Browse the repository at this point in the history
  • Loading branch information
needs committed Jan 4, 2025
1 parent 9c68760 commit 8429a7f
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 48 deletions.
19 changes: 19 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
"command": "workbench.action.tasks.terminate",
"args": "Worker"
},
{
"id": "terminateScheduler",
"type": "command",
"command": "workbench.action.tasks.terminate",
"args": "Scheduler"
},
{
"id": "terminateDocker",
"type": "command",
Expand Down Expand Up @@ -47,6 +53,7 @@
"dependsOn": [
"Terminate Frontend",
"Terminate Worker",
"Terminate Scheduler",
"Terminate Docker"
],
},
Expand All @@ -60,6 +67,11 @@
"type": "process",
"command": "echo ${input:terminateWorker}",
},
{
"label": "Terminate Scheduler",
"type": "process",
"command": "echo ${input:terminateScheduler}",
},
{
"label": "Terminate Docker",
"type": "process",
Expand Down Expand Up @@ -95,6 +107,7 @@
"Start docker",
"Frontend",
"Worker",
"Scheduler",
],
},
{
Expand All @@ -109,5 +122,11 @@
"command": "npx nx serve worker",
"isBackground": true,
},
{
"label": "Scheduler",
"type": "shell",
"command": "npx nx serve scheduler",
"isBackground": true,
},
]
}
8 changes: 2 additions & 6 deletions apps/frontend/app/all/clans/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ export default async function Index({
select: {
name: true,
playTime: true,
_count: {
select: {
players: true,
},
},
activePlayerCount: true,
},
orderBy: [
{
Expand All @@ -44,7 +40,7 @@ export default async function Index({
clans={clans.map((clan, index) => ({
rank: (page - 1) * 100 + index + 1,
name: clan.name,
playerCount: clan._count.players,
playerCount: clan.activePlayerCount,
playTime: clan.playTime,
}))}
/>
Expand Down
15 changes: 3 additions & 12 deletions apps/frontend/app/clan/[clanName]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,7 @@ export default async function Index({
select: {
name: true,
playTime: true,
_count: {
select: {
players: true,
},
},
players: {
select: {
playTime: true,
},
},
activePlayerCount: true,
},
where: {
name: clanName,
Expand Down Expand Up @@ -60,7 +51,7 @@ export default async function Index({
<header className="flex flex-row px-20 gap-4 items-center">
<section className="flex flex-col gap-2 grow">
<h1 className="text-2xl font-bold">{clan.name}</h1>
<span className="pr-4">{`${clan.players.length} players`}</span>
<span className="pr-4">{`${clan.activePlayerCount} players`}</span>
</section>
<aside className="flex flex-col gap-2 text-right">
<p>
Expand All @@ -71,7 +62,7 @@ export default async function Index({

<LayoutTabs
clanName={clanName}
playerCount={clan.players.length}
playerCount={clan.activePlayerCount}
gameTypeCount={gameTypeCount}
mapCount={mapCount}
/>
Expand Down
8 changes: 2 additions & 6 deletions apps/frontend/app/clan/[clanName]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ export default async function Index({

const clan = await prisma.clan.findUnique({
select: {
_count: {
select: {
players: true,
},
},
activePlayerCount: true,
clanPlayerInfos: {
select: {
playTime: true,
Expand Down Expand Up @@ -75,7 +71,7 @@ export default async function Index({

return (
<PlayerList
playerCount={clan._count.players}
playerCount={clan.activePlayerCount}
rankMethod={null}
showLastSeen={true}
players={clan.clanPlayerInfos.map((playerInfo, index) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ export default async function Index({
select: {
clan: {
select: {
_count: {
select: {
players: true,
},
},
activePlayerCount: true,
},
},
clanName: true,
Expand All @@ -59,7 +55,7 @@ export default async function Index({
clans={gameType.clanInfoGameTypes.map((clanInfoGameType, index) => ({
rank: (page - 1) * 100 + index + 1,
name: clanInfoGameType.clanName,
playerCount: clanInfoGameType.clan._count.players,
playerCount: clanInfoGameType.clan.activePlayerCount,
playTime: clanInfoGameType.playTime,
}))}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ export default async function Index({
select: {
clan: {
select: {
_count: {
select: {
players: true,
},
},
activePlayerCount: true,
},
},
clanName: true,
Expand Down Expand Up @@ -62,7 +58,7 @@ export default async function Index({
clans={map.clanInfoMaps.map((clanInfoMap, index) => ({
rank: (page - 1) * 100 + index + 1,
name: clanInfoMap.clanName,
playerCount: clanInfoMap.clan._count.players,
playerCount: clanInfoMap.clan.activePlayerCount,
playTime: clanInfoMap.playTime,
}))}
/>
Expand Down
8 changes: 2 additions & 6 deletions apps/frontend/app/player/[playerName]/clans/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ export default async function Index({
playTime: true,
clan: {
select: {
_count: {
select: {
players: true,
},
},
activePlayerCount: true,
},
},
},
Expand Down Expand Up @@ -71,7 +67,7 @@ export default async function Index({
clans={player.clanPlayerInfos.map((clanPlayerInfo, index) => ({
rank: (page - 1) * 100 + index + 1,
name: clanPlayerInfo.clanName,
playerCount: clanPlayerInfo.clan._count.players,
playerCount: clanPlayerInfo.clan.activePlayerCount,
playTime: clanPlayerInfo.playTime,
}))}
/>
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/utils/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function search(query: string) {
const clans = await prisma.$queryRawTyped(searchClans(`%${query}%`)).then((clans) => {
return clans.map((clan) => ({
...clan,
playerCount: Number(clan.playerCount) || 0,
playerCount: Number(clan.activePlayerCount) || 0,
}));
});

Expand Down
6 changes: 1 addition & 5 deletions libs/prisma/prisma/sql/searchClans.sql
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
SELECT
"public"."Clan"."name",
"public"."Clan"."playTime",
COUNT(DISTINCT "public"."Player"."name") as "playerCount"
"public"."Clan"."activePlayerCount"
FROM
"public"."Clan"
LEFT JOIN "public"."Player" ON "public"."Player"."clanName" = "public"."Clan"."name"
WHERE
"public"."Clan"."name" ILIKE $1
AND "public"."Player"."clanName" IS NOT NULL
GROUP BY
"public"."Clan"."name"
ORDER BY
LENGTH("public"."Clan"."name"),
"public"."Clan"."playTime" DESC
Expand Down

0 comments on commit 8429a7f

Please sign in to comment.