Enhance AI recommendations handling with validation and caching improvements
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
- Introduced a new method to validate company IDs for AI recommendations, ensuring all requested companies exist before processing. - Added caching logic to retrieve AI recommendations efficiently, reducing unnecessary calls and improving performance. - Utilized errgroup for concurrent processing of AI recommendations across multiple companies, enhancing responsiveness. - Updated the tender service to handle rejected tenders more effectively by incorporating concurrent fetching of rejected tender IDs. This update significantly improves the AI recommendations process by ensuring accurate company validation and optimizing data retrieval through caching and concurrency, enhancing overall system performance and user experience.
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
// CompanyRejectedTenderLister returns tender IDs the company has rejected.
|
||||
@@ -46,18 +48,37 @@ func (s *tenderService) buildRejectedTenderIDSet(ctx context.Context, companyID
|
||||
|
||||
func (s *tenderService) buildRejectedTenderIDSetForCompanies(ctx context.Context, companyIDs []string) (map[string]struct{}, error) {
|
||||
excluded := make(map[string]struct{})
|
||||
for _, companyID := range normalizeRecommendationCompanyScope(companyIDs) {
|
||||
if s.rejectedTenderLister == nil {
|
||||
return excluded, nil
|
||||
}
|
||||
if s.rejectedTenderLister == nil {
|
||||
return excluded, nil
|
||||
}
|
||||
|
||||
ids, err := s.rejectedTenderLister.ListRejectedTenderIDsByCompanyID(ctx, companyID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to list rejected tender exclusions: %w", err)
|
||||
}
|
||||
normalized := normalizeRecommendationCompanyScope(companyIDs)
|
||||
if len(normalized) == 0 {
|
||||
return excluded, nil
|
||||
}
|
||||
|
||||
results := make([][]string, len(normalized))
|
||||
group, groupCtx := errgroup.WithContext(ctx)
|
||||
for i, companyID := range normalized {
|
||||
i := i
|
||||
companyID := companyID
|
||||
group.Go(func() error {
|
||||
ids, err := s.rejectedTenderLister.ListRejectedTenderIDsByCompanyID(groupCtx, companyID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to list rejected tender exclusions: %w", err)
|
||||
}
|
||||
results[i] = ids
|
||||
return nil
|
||||
})
|
||||
}
|
||||
if err := group.Wait(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, ids := range results {
|
||||
addTenderIDsToSet(excluded, ids)
|
||||
}
|
||||
|
||||
return excluded, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user