Refactor recommendation response handling and enhance enrichment logic
continuous-integration/drone/push Build is passing

- Removed the `buildRecommendedTenderResponsesParallel` method and replaced it with `buildRecommendedTenderListResponses`, simplifying the response building process.
- Introduced `enrichRecommendedTenderResponsesParallel` to handle enrichment of tender responses in parallel, improving performance.
- Updated the `Recommend` method to utilize the new enrichment logic, ensuring timely and efficient processing of recommendations.
- Cleaned up unused functions and imports in `recommendation_page_cache.go` and `recommendation_response.go`, enhancing code clarity and maintainability.

This update streamlines the recommendation response handling and improves the overall efficiency of the tender recommendation service.
This commit is contained in:
Mazyar
2026-07-08 02:27:25 +03:30
parent 784c3d6563
commit f68b6d7787
3 changed files with 91 additions and 72 deletions
+17 -4
View File
@@ -96,8 +96,9 @@ type tenderService struct {
}
const (
aiSummaryEnrichmentTimeout = 2 * time.Second
aiTranslationEnrichmentTimeout = 2 * time.Second
aiSummaryEnrichmentTimeout = 2 * time.Second
aiTranslationEnrichmentTimeout = 2 * time.Second
recommendTranslationEnrichmentTimeout = 5 * time.Second
)
var (
@@ -214,6 +215,17 @@ func (s *tenderService) enrichWithAISummary(ctx context.Context, t *Tender, resp
// enrichWithTranslation overlays title/description from MinIO when the pipeline has finished
// for the requested language. Does not call the AI translate API on GET.
func (s *tenderService) enrichWithTranslation(ctx context.Context, t *Tender, resp *TenderResponse, language string, cache *recommendationTranslationCache) {
s.enrichWithTranslationTimeout(ctx, t, resp, language, cache, aiTranslationEnrichmentTimeout)
}
func (s *tenderService) enrichWithTranslationTimeout(
ctx context.Context,
t *Tender,
resp *TenderResponse,
language string,
cache *recommendationTranslationCache,
enrichmentTimeout time.Duration,
) {
if t == nil || resp == nil {
return
}
@@ -233,7 +245,7 @@ func (s *tenderService) enrichWithTranslation(ctx context.Context, t *Tender, re
}
}
enrichCtx, cancel := context.WithTimeout(ctx, aiTranslationEnrichmentTimeout)
enrichCtx, cancel := context.WithTimeout(ctx, enrichmentTimeout)
defer cancel()
stored, usedNotice, err := s.lookupTranslationForTender(enrichCtx, t, targetLanguage)
@@ -1027,7 +1039,8 @@ func (s *tenderService) Recommend(ctx context.Context, form *SearchForm, paginat
return nil, err
}
paged := s.buildRecommendedTenderResponsesParallel(ctx, pageResult.items, lang)
paged := s.buildRecommendedTenderListResponses(pageResult.items, lang)
paged = s.enrichRecommendedTenderResponsesParallel(ctx, paged, lang)
return &SearchResponse{
Tenders: paged,