refactor: game page reads presets from performanceEntries where settingsJson is not null
This commit is contained in:
@@ -64,8 +64,6 @@ interface PlatformSupport {
|
|||||||
|
|
||||||
interface Preset {
|
interface Preset {
|
||||||
id: string
|
id: string
|
||||||
name: string
|
|
||||||
description: string | null
|
|
||||||
hardwareSlug: string
|
hardwareSlug: string
|
||||||
hardwareName: string
|
hardwareName: string
|
||||||
upvotes: number
|
upvotes: number
|
||||||
@@ -185,6 +183,12 @@ function getFpsColor(preset: Preset): string {
|
|||||||
return "text-text/60"
|
return "text-text/60"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function generatePresetName(preset: Preset): string {
|
||||||
|
const parts = [preset.hardwareName]
|
||||||
|
if (preset.fpsAvg !== null) parts.push(`${Math.round(preset.fpsAvg)}fps`)
|
||||||
|
return parts.join(" · ")
|
||||||
|
}
|
||||||
|
|
||||||
export function GamePageClient({
|
export function GamePageClient({
|
||||||
game,
|
game,
|
||||||
counts,
|
counts,
|
||||||
@@ -833,7 +837,7 @@ export function GamePageClient({
|
|||||||
<div className='min-w-0'>
|
<div className='min-w-0'>
|
||||||
<div className='flex items-center gap-2'>
|
<div className='flex items-center gap-2'>
|
||||||
<h3 className='font-semibold text-sm truncate'>
|
<h3 className='font-semibold text-sm truncate'>
|
||||||
{preset.name}
|
{generatePresetName(preset)}
|
||||||
</h3>
|
</h3>
|
||||||
{raw && (
|
{raw && (
|
||||||
<span className='inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full bg-green-500/10 border border-green-500/20 text-green-400 text-[9px] font-semibold'>
|
<span className='inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full bg-green-500/10 border border-green-500/20 text-green-400 text-[9px] font-semibold'>
|
||||||
|
|||||||
+25
-23
@@ -5,12 +5,11 @@ import {
|
|||||||
games,
|
games,
|
||||||
gameVersions,
|
gameVersions,
|
||||||
performanceEntries,
|
performanceEntries,
|
||||||
communityPresets,
|
|
||||||
gameComments,
|
gameComments,
|
||||||
gamePlatformSupport,
|
gamePlatformSupport,
|
||||||
hardware,
|
hardware,
|
||||||
} from "@/lib/db/schema"
|
} from "@/lib/db/schema"
|
||||||
import { eq, sql } from "drizzle-orm"
|
import { and, desc, eq, sql } from "drizzle-orm"
|
||||||
import { isSyncStale, syncSteamGame } from "@/lib/steam/sync"
|
import { isSyncStale, syncSteamGame } from "@/lib/steam/sync"
|
||||||
import { GamePageClient } from "./game-page-client"
|
import { GamePageClient } from "./game-page-client"
|
||||||
|
|
||||||
@@ -149,8 +148,15 @@ export default async function GamePage({
|
|||||||
.then((r) => r[0]?.count ?? 0),
|
.then((r) => r[0]?.count ?? 0),
|
||||||
db
|
db
|
||||||
.select({ count: sql<number>`count(*)::int` })
|
.select({ count: sql<number>`count(*)::int` })
|
||||||
.from(communityPresets)
|
.from(performanceEntries)
|
||||||
.where(eq(communityPresets.gameId, game.id))
|
.innerJoin(gameVersions, eq(performanceEntries.versionId, gameVersions.id))
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(gameVersions.gameId, game.id),
|
||||||
|
eq(performanceEntries.isRemoved, false),
|
||||||
|
sql`${performanceEntries.settingsJson} IS NOT NULL`,
|
||||||
|
),
|
||||||
|
)
|
||||||
.then((r) => r[0]?.count ?? 0),
|
.then((r) => r[0]?.count ?? 0),
|
||||||
db
|
db
|
||||||
.select({ count: sql<number>`count(*)::int` })
|
.select({ count: sql<number>`count(*)::int` })
|
||||||
@@ -164,14 +170,11 @@ export default async function GamePage({
|
|||||||
.then((r) => r),
|
.then((r) => r),
|
||||||
db
|
db
|
||||||
.select({
|
.select({
|
||||||
id: communityPresets.id,
|
id: performanceEntries.id,
|
||||||
name: communityPresets.name,
|
hardwareSlug: performanceEntries.hardwareSlug,
|
||||||
description: communityPresets.description,
|
|
||||||
hardwareSlug: communityPresets.hardwareSlug,
|
|
||||||
hardwareName: hardware.name,
|
hardwareName: hardware.name,
|
||||||
upvotes: communityPresets.upvotes,
|
upvotes: performanceEntries.upvotes,
|
||||||
settingsJson: communityPresets.settingsJson,
|
settingsJson: performanceEntries.settingsJson,
|
||||||
createdAt: communityPresets.createdAt,
|
|
||||||
fpsAvg: performanceEntries.fpsAvg,
|
fpsAvg: performanceEntries.fpsAvg,
|
||||||
fpsLow: performanceEntries.fpsLow,
|
fpsLow: performanceEntries.fpsLow,
|
||||||
fpsHigh: performanceEntries.fpsHigh,
|
fpsHigh: performanceEntries.fpsHigh,
|
||||||
@@ -180,18 +183,19 @@ export default async function GamePage({
|
|||||||
frameGenMethod: performanceEntries.frameGenMethod,
|
frameGenMethod: performanceEntries.frameGenMethod,
|
||||||
protonVersion: performanceEntries.protonVersion,
|
protonVersion: performanceEntries.protonVersion,
|
||||||
osVersion: performanceEntries.osVersion,
|
osVersion: performanceEntries.osVersion,
|
||||||
|
createdAt: performanceEntries.createdAt,
|
||||||
})
|
})
|
||||||
.from(communityPresets)
|
.from(performanceEntries)
|
||||||
.leftJoin(
|
.innerJoin(gameVersions, eq(performanceEntries.versionId, gameVersions.id))
|
||||||
performanceEntries,
|
.innerJoin(hardware, eq(performanceEntries.hardwareSlug, hardware.slug))
|
||||||
eq(communityPresets.performanceEntryId, performanceEntries.id),
|
.where(
|
||||||
|
and(
|
||||||
|
eq(gameVersions.gameId, game.id),
|
||||||
|
eq(performanceEntries.isRemoved, false),
|
||||||
|
sql`${performanceEntries.settingsJson} IS NOT NULL`,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.innerJoin(
|
.orderBy(desc(performanceEntries.upvotes)),
|
||||||
hardware,
|
|
||||||
eq(communityPresets.hardwareSlug, hardware.slug),
|
|
||||||
)
|
|
||||||
.where(eq(communityPresets.gameId, game.id))
|
|
||||||
.orderBy(sql`${communityPresets.upvotes} DESC`),
|
|
||||||
])
|
])
|
||||||
|
|
||||||
// ── Sync logic: force or stale-while-revalidate ─────────────────
|
// ── Sync logic: force or stale-while-revalidate ─────────────────
|
||||||
@@ -226,8 +230,6 @@ export default async function GamePage({
|
|||||||
|
|
||||||
const serializedPresets = presetRows.map((p) => ({
|
const serializedPresets = presetRows.map((p) => ({
|
||||||
id: p.id,
|
id: p.id,
|
||||||
name: p.name,
|
|
||||||
description: p.description,
|
|
||||||
hardwareSlug: p.hardwareSlug,
|
hardwareSlug: p.hardwareSlug,
|
||||||
hardwareName: p.hardwareName,
|
hardwareName: p.hardwareName,
|
||||||
upvotes: p.upvotes,
|
upvotes: p.upvotes,
|
||||||
|
|||||||
Reference in New Issue
Block a user