Add cache staleness check for recommendation page
continuous-integration/drone/push Build is passing

- Introduced a new method `isRecommendedPageCacheStale` in the `tenderService` to determine if the cached recommendations for a company are outdated based on the count of cached recommendations and the latest AI recommendations.
- Updated the `recommendFromPageCache` method to utilize the new cache staleness check, ensuring that outdated caches are not used for recommendations.
- This enhancement improves the accuracy of recommendations by ensuring that users receive the most up-to-date information, thereby enhancing the overall user experience in the tender recommendation service.
This commit is contained in:
Mazyar
2026-07-08 02:41:00 +03:30
parent f68b6d7787
commit 11e0b44ebe
@@ -201,6 +201,20 @@ func (s *tenderService) buildAllRankedRecommendations(
return out, nil
}
func (s *tenderService) isRecommendedPageCacheStale(ctx context.Context, companyID string, cachedCount int) bool {
companyID = strings.TrimSpace(companyID)
if companyID == "" || cachedCount == 0 {
return false
}
recommendations, err := s.companyService.GetAIRecommendations(ctx, companyID)
if err != nil || len(recommendations) == 0 {
return false
}
return cachedCount < len(recommendations)
}
func (s *tenderService) recommendFromPageCache(
ctx context.Context,
companyID string,
@@ -223,6 +237,10 @@ func (s *tenderService) recommendFromPageCache(
return nil, false
}
if len(companyIDs) == 0 && s.isRecommendedPageCacheStale(ctx, companyID, len(cached)) {
return nil, false
}
excluded, excludedByCompany, err := s.loadRecommendationExclusions(ctx, form, companyID, companyIDs)
if err != nil {
return nil, false