Enhance tender recommendation service with caching and parallel processing
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
- Introduced a caching mechanism for translation responses in the tender recommendation service, improving efficiency by reducing redundant translation requests. - Refactored the `enrichWithTranslation` method to support an optional translation cache, allowing for faster retrieval of stored translations. - Implemented parallel processing for building recommended tender responses, utilizing goroutines to enhance performance and responsiveness. - Added unit tests to validate the new caching behavior and ensure the correct application of translations in various scenarios. This update significantly improves the performance and responsiveness of the tender recommendation service by integrating caching and parallel processing, enhancing the overall user experience.
This commit is contained in:
@@ -191,6 +191,10 @@ func (s *companyService) GetAIRecommendations(ctx context.Context, companyID str
|
||||
return nil, errors.New("company ID is required")
|
||||
}
|
||||
|
||||
if cached, ok := s.getCachedAIRecommendations(ctx, companyID); ok {
|
||||
return cached, nil
|
||||
}
|
||||
|
||||
if _, err := s.repository.GetByID(ctx, companyID); err != nil {
|
||||
s.logger.Error("Failed to load company for AI recommendations", map[string]interface{}{
|
||||
"company_id": companyID,
|
||||
@@ -199,11 +203,7 @@ func (s *companyService) GetAIRecommendations(ctx context.Context, companyID str
|
||||
return nil, errors.New("company not found")
|
||||
}
|
||||
|
||||
if cached, ok := s.getCachedAIRecommendations(ctx, companyID); ok {
|
||||
return cached, nil
|
||||
}
|
||||
|
||||
s.logger.Info("AI recommendations cache miss; returning empty list", map[string]interface{}{
|
||||
s.logger.Debug("AI recommendations cache miss; returning empty list", map[string]interface{}{
|
||||
"company_id": companyID,
|
||||
})
|
||||
|
||||
@@ -234,7 +234,7 @@ func (s *companyService) getCachedAIRecommendationsOrEmpty(ctx context.Context,
|
||||
return cached
|
||||
}
|
||||
|
||||
s.logger.Info("AI recommendations cache miss; returning empty list", map[string]interface{}{
|
||||
s.logger.Debug("AI recommendations cache miss; returning empty list", map[string]interface{}{
|
||||
"company_id": companyID,
|
||||
})
|
||||
return []RecommendedTenderResponse{}
|
||||
@@ -251,12 +251,11 @@ func (s *companyService) GetMergedAIRecommendations(ctx context.Context, company
|
||||
return []RecommendedTenderResponse{}, nil
|
||||
}
|
||||
|
||||
if err := s.validateRecommendationCompanyIDs(ctx, normalized); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
recommendationLists := make([][]RecommendedTenderResponse, len(normalized))
|
||||
group, groupCtx := errgroup.WithContext(ctx)
|
||||
group.Go(func() error {
|
||||
return s.validateRecommendationCompanyIDs(groupCtx, normalized)
|
||||
})
|
||||
for i, companyID := range normalized {
|
||||
i := i
|
||||
companyID := companyID
|
||||
|
||||
Reference in New Issue
Block a user