perf: prevent duplicate CDN uploads by checking Supabase first

This commit is contained in:
mstfyldz
2026-08-12 10:41:08 +03:00
parent b86aa54378
commit 6916a7d9ba
+17
View File
@@ -146,6 +146,23 @@ export const cachePrecedentDocument = async (req: Request, res: Response) => {
}
const documentId = String(item.documentId);
// 0. Duplicate Kontrolü (Veritabanında var mı?)
try {
const { data: existing } = await supabase
.from('cached_precedents')
.select('document_id')
.eq('document_id', documentId)
.single();
if (existing) {
console.log(`[Cache] Karar zaten arşivde mevcut, işlem atlandı: ${documentId}`);
return res.json({ success: true, message: 'Zaten ön bellekte', cached: true });
}
} catch (err) {
// Eğer tablo boşsa veya hata verirse devam et, sorun yok.
}
// 1. BunnyCDN'e Yükle
const bunnyZone = process.env.BUNNY_STORAGE_ZONE || '';
const bunnyKey = process.env.BUNNY_STORAGE_API_KEY || '';