From a37e02aea91493664bbab53c3a405eff7383b808 Mon Sep 17 00:00:00 2001 From: AI Assistant Date: Mon, 16 Mar 2026 13:55:10 +0900 Subject: [PATCH] Trim heavy search stages to avoid 504 --- TODO.md | 11 +++++++++++ backend/services/cse.go | 6 +++--- backend/services/ranker.go | 2 +- backend/services/search_collectors.go | 6 +++--- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/TODO.md b/TODO.md index 81be64c..57784e2 100644 --- a/TODO.md +++ b/TODO.md @@ -341,6 +341,17 @@ - [ ] full browser-level validation was not fully reproducible in this environment ## Recent Change Log +- Date: `2026-03-16` +- What changed: + - Reduced the heaviest search-stage caps slightly: fewer query variants per request, smaller per-source result caps, lower enrichment scope, and a bounded Gemini candidate set. +- Why it changed: + - The widened search configuration was pushing the request past the reverse-proxy timeout and surfacing `504 Gateway Time-out`. +- How it was verified: + - `go test ./...` + - `bash scripts/selftest.sh` +- What is still risky or incomplete: + - Search coverage is still broader than the original baseline, but there is now an explicit tradeoff between result volume and request latency. + - Date: `2026-03-16` - What changed: - Increased collector result caps and widened source-specific search query templates for Envato, Artgrid, and Google Video. diff --git a/backend/services/cse.go b/backend/services/cse.go index 9f4d295..7dc1780 100644 --- a/backend/services/cse.go +++ b/backend/services/cse.go @@ -64,9 +64,9 @@ func (s *SearchService) SearchMedia(queries []string, enabledPlatforms map[strin results := make([]SearchResult, 0, 90) var lastErr error - baseQueries := limitQueries(queries, 10) + baseQueries := limitQueries(queries, 8) shuffleStrings(baseQueries) - primaryQueries := baseQueries[:minInt(len(baseQueries), 5)] + primaryQueries := baseQueries[:minInt(len(baseQueries), 4)] runSearchPass := func(bases []string, onlyMissing bool) { for _, base := range bases { base = strings.TrimSpace(base) @@ -127,7 +127,7 @@ func (s *SearchService) SearchMedia(queries []string, enabledPlatforms map[strin } func (s *SearchService) EnrichResults(results []SearchResult) []SearchResult { - limit := minInt(len(results), 18) + limit := minInt(len(results), 12) if limit == 0 { return results } diff --git a/backend/services/ranker.go b/backend/services/ranker.go index 87a64b9..07f1035 100644 --- a/backend/services/ranker.go +++ b/backend/services/ranker.go @@ -87,7 +87,7 @@ func RankSearchResults(query string, results []SearchResult) []SearchResult { } func GeminiCandidateLimit(total int) int { - return total + return min(total, 12) } func EvaluateAllCandidatesWithGemini(service *GeminiService, query string, ranked []SearchResult) ([]AIRecommendation, GeminiBatchStats, error) { diff --git a/backend/services/search_collectors.go b/backend/services/search_collectors.go index a65dfea..75c61a5 100644 --- a/backend/services/search_collectors.go +++ b/backend/services/search_collectors.go @@ -15,7 +15,7 @@ type searchCollector interface { type envatoCollector struct{} func (envatoCollector) Name() string { return "Envato" } -func (envatoCollector) MaxResults() int { return 14 } +func (envatoCollector) MaxResults() int { return 10 } func (envatoCollector) Enabled(enabledPlatforms map[string]bool) bool { return len(enabledPlatforms) == 0 || enabledPlatforms["envato"] } @@ -31,7 +31,7 @@ func (envatoCollector) Enrich(searcher *SearchService, result SearchResult) Sear type artgridCollector struct{} func (artgridCollector) Name() string { return "Artgrid" } -func (artgridCollector) MaxResults() int { return 14 } +func (artgridCollector) MaxResults() int { return 10 } func (artgridCollector) Enabled(enabledPlatforms map[string]bool) bool { return len(enabledPlatforms) == 0 || enabledPlatforms["artgrid"] } @@ -47,7 +47,7 @@ func (artgridCollector) Enrich(searcher *SearchService, result SearchResult) Sea type googleVideoCollector struct{} func (googleVideoCollector) Name() string { return "Google Video" } -func (googleVideoCollector) MaxResults() int { return 10 } +func (googleVideoCollector) MaxResults() int { return 8 } func (googleVideoCollector) Enabled(enabledPlatforms map[string]bool) bool { return len(enabledPlatforms) == 0 || enabledPlatforms["google video"] }