fix: limit recommendation scoring

This commit is contained in:
2026-06-16 01:25:46 +02:00
committed by Milas Holsting
parent c1e313d684
commit 7c25907c92
3 changed files with 24 additions and 2 deletions

View File

@@ -64,7 +64,7 @@ func (e engine) getTopPicksForYou(ctx context.Context, userID string, resultLimi
return domain.CatalogSectionData{Animes: []domain.Anime{}}, nil
}
candidates, err := e.scoreRankedCandidates(ctx, now, profile, ranked)
candidates, err := e.scoreRankedCandidates(ctx, now, profile, ranked, resultLimit)
if err != nil {
return domain.CatalogSectionData{}, err
}
@@ -191,8 +191,9 @@ func (e engine) scoreRankedCandidates(
now time.Time,
profile userTasteProfile,
ranked []rankedCandidate,
resultLimit int,
) ([]recommendationCandidate, error) {
limit := min(len(ranked), candidateFetchLimit)
limit := min(len(ranked), candidateScoreLimit(resultLimit))
candidates := make([]recommendationCandidate, 0, limit)
var candidatesMu sync.Mutex
var g errgroup.Group
@@ -244,3 +245,11 @@ func (e engine) scoreRankedCandidates(
return candidates, nil
}
func candidateScoreLimit(resultLimit int) int {
if resultLimit <= 0 {
return 0
}
return min(candidateFetchLimit, resultLimit+candidateFetchBuffer)
}