Add handling for nil TosHighlights in ComputeScore function

This commit is contained in:
pluja 2023-11-12 22:13:41 +01:00
parent 68a31df2e8
commit c91f0b4613

View File

@ -8,6 +8,7 @@ import (
"pluja.dev/kycnot.me/database" "pluja.dev/kycnot.me/database"
"pluja.dev/kycnot.me/ent" "pluja.dev/kycnot.me/ent"
"pluja.dev/kycnot.me/ent/schema"
) )
func ComputeScore(s *ent.Service) int { func ComputeScore(s *ent.Service) int {
@ -41,6 +42,9 @@ func ComputeScore(s *ent.Service) int {
} }
// Tos Highlights Penalty // Tos Highlights Penalty
if s.TosHighlights == nil {
s.TosHighlights = &[]schema.TosHighlight{}
}
nTosH := len(*s.TosHighlights) nTosH := len(*s.TosHighlights)
nTosPenalty := float64(nTosH) * bonusMedium // Each 2 TOS highlights, decrease the score by 1 nTosPenalty := float64(nTosH) * bonusMedium // Each 2 TOS highlights, decrease the score by 1
if nTosPenalty > maxTosPenalty { if nTosPenalty > maxTosPenalty {