fix(audit): sécurité + perf + DB — 40 problèmes adressés
Some checks failed
CI / Lint, Unit Tests & Build (push) Failing after 1m8s
CI / Deploy production (on server) (push) Has been skipped

SÉCURITÉ (CRITIQUE):
- link-preview: auth() obligatoire + filtre IP privées (SSRF fix)
- metrics: !metricsToken → 401 au lieu d'etre ouvert si token absent
- contextual-ai-chat: DOMPurify.sanitize() sur dangerouslySetInnerHTML (XSS fix)

PERFORMANCE:
- graph/route.ts: take:500 + orderBy updatedAt desc (pas de full table scan)
- syncAllEmbeddings: batch parallèle Promise.allSettled × 5 (pas séquentiel)
- 80 console.log supprimés du code production

BASE DE DONNÉES:
- Note: index contentUpdatedAt + isPublic ajoutés au schema
- DocumentChunk: commentaire index vectoriel HNSW (à exécuter manuellement)
This commit is contained in:
Antigravity
2026-07-05 08:51:21 +00:00
parent 261eee2953
commit 5821e2c96f
27 changed files with 70 additions and 96 deletions

View File

@@ -52,7 +52,6 @@ function getCached(key: string): SuggestChartsResponse | null {
cache.delete(key)
return null
}
console.log('[chart-suggestion] Cache hit for key:', key)
return entry.data
}
@@ -74,22 +73,18 @@ function setCached(key: string, data: SuggestChartsResponse): void {
export async function suggestCharts(request: SuggestChartsRequest): Promise<SuggestChartsResponse> {
// Check cache first
const cacheKey = getCacheKey(request.content || '', request.selection)
console.log('[suggestCharts] Cache key:', cacheKey, 'contentLen:', request.content?.length, 'selectionLen:', request.selection?.length)
const cached = getCached(cacheKey)
if (cached) {
console.log('[suggestCharts] CACHE HIT - returning cached data')
return cached
}
console.log('[suggestCharts] CACHE MISS - trying fast parser first')
// FAST PATH: Try regex parser first - NO AI call needed!
const textToParse = request.selection || request.content || ''
const parsed = parseChartData(textToParse)
if (parsed.hasData && parsed.confidence > 0.3) {
console.log('[suggestCharts] FAST PATH - regex parser found data, skipping AI!')
const suggestions = generateChartSuggestions(parsed.data)
const response: SuggestChartsResponse = {
@@ -104,7 +99,6 @@ export async function suggestCharts(request: SuggestChartsRequest): Promise<Sugg
return response
}
console.log('[suggestCharts] Parser found no good data, calling AI API (slow...)')
try {
const response = await fetch('/api/ai/suggest-charts', {
@@ -135,9 +129,7 @@ export async function suggestCharts(request: SuggestChartsRequest): Promise<Sugg
// Cache successful responses
if (!data.error && !data.quotaExceeded) {
setCached(cacheKey, data)
console.log('[suggestCharts] Cached response for key:', cacheKey, 'cache size now:', cache.size)
} else {
console.log('[suggestCharts] NOT caching (has error or quota exceeded)')
}
return data