From 11e0b44ebeb23246b5685e6601a7295aa5127e00 Mon Sep 17 00:00:00 2001 From: Mazyar Date: Wed, 8 Jul 2026 02:41:00 +0330 Subject: [PATCH] Add cache staleness check for recommendation page - 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. --- internal/tender/recommendation_page_cache.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/internal/tender/recommendation_page_cache.go b/internal/tender/recommendation_page_cache.go index 4f51636..d360f56 100644 --- a/internal/tender/recommendation_page_cache.go +++ b/internal/tender/recommendation_page_cache.go @@ -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