recuperando informacion y tratandola

This commit is contained in:
2026-06-11 16:38:36 +02:00
parent cabd4803a4
commit de9d998650
7 changed files with 346 additions and 100 deletions
+36 -25
View File
@@ -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);
}
}