33import db from "@/db/index" ;
44import { gameState } from "@/db/schema" ;
55import { redirect } from "next/navigation" ;
6- import { unstable_cache , revalidateTag } from "next/cache" ;
76import { eq } from "drizzle-orm" ;
87
9- // Internal helper to fetch (and lazily create) the GameState row.
10- async function fetchCurrentRoundFromDB ( ) : Promise < number > {
8+ // Get current round directly from database
9+ export async function getCurrentRound ( ) : Promise < number > {
1110 const gameStateResult = await db . select ( ) . from ( gameState ) . limit ( 1 ) ;
1211 if ( ! gameStateResult . length ) {
1312 const result = await db
@@ -22,17 +21,7 @@ async function fetchCurrentRoundFromDB(): Promise<number> {
2221 return gameStateResult [ 0 ] . currentRound ;
2322}
2423
25- // Cached getter using unstable_cache with an explicit tag so we can invalidate on round advance.
26- // The cache key array value "game-state-current-round" is arbitrary but must stay stable.
27- export const getCurrentRound = unstable_cache (
28- async ( ) => {
29- return await fetchCurrentRoundFromDB ( ) ;
30- } ,
31- [ "game-state-current-round" ] ,
32- { tags : [ "currentRound" ] }
33- ) ;
34-
35- // Advance to the next round and invalidate the cached value.
24+ // Advance to the next round.
3625// Optionally accept an explicit nextRound (e.g. for admin controls) otherwise increments by 1.
3726export async function advanceRound ( nextRound ?: number ) {
3827 // Ensure a row exists and get its id & current value.
@@ -65,9 +54,6 @@ export async function advanceRound(nextRound?: number) {
6554 } )
6655 . where ( eq ( gameState . id , gameStateRecord . id ) ) ;
6756
68- // Invalidate the cached round so subsequent calls see the fresh value.
69- revalidateTag ( "currentRound" ) ;
70-
7157 return newRound ;
7258}
7359
0 commit comments