Add cache staleness check for recommendation page
continuous-integration/drone/push Build is passing
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user