recuperando informacion y tratandola
This commit is contained in:
+36
-25
@@ -7,20 +7,27 @@ export async function getCachedCard<T>(
|
||||
movieId: number,
|
||||
cardType: CardType,
|
||||
): Promise<T | null> {
|
||||
const db = getDb();
|
||||
const rows = await db
|
||||
.select()
|
||||
.from(cardCache)
|
||||
.where(
|
||||
and(eq(cardCache.movieId, movieId), eq(cardCache.cardType, cardType)),
|
||||
)
|
||||
.limit(1);
|
||||
try {
|
||||
const db = getDb();
|
||||
const rows = await db
|
||||
.select()
|
||||
.from(cardCache)
|
||||
.where(
|
||||
and(eq(cardCache.movieId, movieId), eq(cardCache.cardType, cardType)),
|
||||
)
|
||||
.limit(1);
|
||||
|
||||
if (rows.length === 0) {
|
||||
if (rows.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return rows[0].payload as T;
|
||||
} catch (err) {
|
||||
// DB may be unavailable in local dev (e.g. DATABASE_URL points to Docker 'db' host).
|
||||
// Treat as cache miss so card generation can still proceed via LLM.
|
||||
console.warn(`[cache] getCachedCard(${movieId}, ${cardType}) skipped:`, err);
|
||||
return null;
|
||||
}
|
||||
|
||||
return rows[0].payload as T;
|
||||
}
|
||||
|
||||
export async function setCachedCard<T>(
|
||||
@@ -28,20 +35,24 @@ export async function setCachedCard<T>(
|
||||
cardType: CardType,
|
||||
payload: T,
|
||||
): Promise<void> {
|
||||
const db = getDb();
|
||||
try {
|
||||
const db = getDb();
|
||||
|
||||
await db
|
||||
.insert(cardCache)
|
||||
.values({
|
||||
movieId,
|
||||
cardType,
|
||||
payload,
|
||||
})
|
||||
.onConflictDoUpdate({
|
||||
target: [cardCache.movieId, cardCache.cardType],
|
||||
set: {
|
||||
await db
|
||||
.insert(cardCache)
|
||||
.values({
|
||||
movieId,
|
||||
cardType,
|
||||
payload,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
});
|
||||
})
|
||||
.onConflictDoUpdate({
|
||||
target: [cardCache.movieId, cardCache.cardType],
|
||||
set: {
|
||||
payload,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
console.warn(`[cache] setCachedCard(${movieId}, ${cardType}) skipped:`, err);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user