perf: prevent duplicate CDN uploads by checking Supabase first
This commit is contained in:
@@ -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 || '';
|
||||
|
||||
Reference in New Issue
Block a user