Enhance tender recommendation caching and page refresh logic
continuous-integration/drone/push Build is passing

- Introduced a new `RecommendedTendersPageCacheRefresher` interface to manage the asynchronous refresh of recommendation pages in Redis, improving cache management.
- Updated the `companyService` to support setting page cache languages and refreshing the recommended tenders page cache based on company IDs.
- Enhanced the `tenderService` to build and invalidate recommended tenders page caches, ensuring timely updates and efficient retrieval of cached recommendations.
- Added configuration options for recommendation page cache languages in the `AISummarizerConfig`, allowing for flexible language support.
- Implemented unit tests for the new caching logic and page refresh functionality, ensuring robust validation of the recommendation caching process.

This update significantly improves the efficiency and responsiveness of the tender recommendation service by integrating enhanced caching mechanisms and page refresh capabilities.
This commit is contained in:
Mazyar
2026-07-08 02:05:36 +03:30
parent b28bc23975
commit 0b74e9ad23
11 changed files with 628 additions and 15 deletions
@@ -0,0 +1,54 @@
package tender
import (
"testing"
"go.mongodb.org/mongo-driver/v2/bson"
)
func TestFilterCachedRecommendedTendersAppliesActiveAndRejectedFilters(t *testing.T) {
activeID, _ := bson.ObjectIDFromHex("507f1f77bcf86cd799439011")
expiredID, _ := bson.ObjectIDFromHex("507f1f77bcf86cd799439012")
items := []TenderResponse{
{
ID: activeID.Hex(),
Status: TenderStatusActive,
PublicationDate: 1,
SubmissionDeadline: 9999999999,
ProcedureRef: "PROC_folder-a/notice-a",
Rank: 1,
},
{
ID: expiredID.Hex(),
Status: TenderStatusExpired,
ProcedureRef: "PROC_folder-b/notice-b",
Rank: 2,
},
}
form := &SearchForm{
OnlyActiveDeadlines: true,
ExcludeRejectedTenders: true,
Status: []string{string(TenderStatusActive)},
}
excluded := map[string]struct{}{expiredID.Hex(): {}}
got := filterCachedRecommendedTenders(items, form, nil, excluded, nil, 100)
if len(got) != 1 {
t.Fatalf("len = %d, want 1", len(got))
}
if got[0].ID != activeID.Hex() {
t.Fatalf("got ID %q, want active tender", got[0].ID)
}
}
func TestParsePageCacheLanguagesConfig(t *testing.T) {
got := ParsePageCacheLanguagesConfig("en,fr, en")
if len(got) != 2 {
t.Fatalf("len = %d, want 2", len(got))
}
if got[0] != "en" || got[1] != "fr" {
t.Fatalf("got %v, want [en fr]", got)
}
}