Skip to content

Commit

Permalink
app models game.server: remove num rounds from home for performance
Browse files Browse the repository at this point in the history
  • Loading branch information
cmnord committed Jul 11, 2023
1 parent 53854ab commit 7e97481
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
10 changes: 4 additions & 6 deletions app/models/game.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,13 @@ export async function getGames(
search: string | null;
},
accessToken?: AuthSession["accessToken"]
): Promise<Game[]> {
) {
const { search, page } = options;
const { from, to } = getPagination(page);

let query = getSupabase(accessToken)
.from<"games", GameTable>("games")
.select<"*, categories ( *, clues ( * ) )", GameAndClues>(
"*, categories ( *, clues ( * ) )"
)
.from("games")
.select()
.order("created_at", { ascending: false })
.range(from, to);

Expand All @@ -288,7 +286,7 @@ export async function getGames(
throw new Error(error.message);
}

return data.map((gac) => dbGameToGame(gac));
return data;
}

/* Writes */
Expand Down
16 changes: 2 additions & 14 deletions app/routes/_index/game-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@ import * as React from "react";

import { GameVisibilityTag } from "~/components/game-visibility-icon";
import { LoadingSpinner } from "~/components/icons";
import type { Game } from "~/models/game.server";
import type { DbGame } from "~/models/game.server";

export default function GameCard({
game,
solo,
}: {
game: Game;
game: DbGame;
solo: boolean;
}) {
const numRounds = game.boards.length;

const [loading, setLoading] = React.useState(false);
const to = solo ? `/game/${game.id}/solo` : `/game/${game.id}/play`;

Expand Down Expand Up @@ -46,16 +44,6 @@ export default function GameCard({
{game.visibility !== "PUBLIC" && (
<GameVisibilityTag visibility={game.visibility} />
)}
<p className="text-sm text-slate-500">
{numRounds} {numRounds === 1 ? "round" : "rounds"} (
{game.boards
.map(
(b) =>
`${b.categories.length}x${b.categories[0].clues.length}`
)
.join(", ")}
)
</p>
</div>
</div>
</Link>
Expand Down
4 changes: 4 additions & 0 deletions app/routes/game/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import { BASE_URL, getRedirectTo, safeRedirect } from "~/utils";

import { newUploadHandler } from "./file-upload-handler.server";

export async function loader() {
throw redirect("/");
}

/** POST /game parses and uploads a new game to the server. */
export async function action({ request }: ActionArgs) {
const authSession = await getValidAuthSession(request);
Expand Down

1 comment on commit 7e97481

@vercel
Copy link

@vercel vercel bot commented on 7e97481 Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.