From c91f0b4613c0d54d94eb8cf7f1c356e16a5eaefe Mon Sep 17 00:00:00 2001 From: pluja Date: Sun, 12 Nov 2023 22:13:41 +0100 Subject: [PATCH] Add handling for nil TosHighlights in ComputeScore function --- src/utils/score.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/utils/score.go b/src/utils/score.go index 0976103..b973618 100644 --- a/src/utils/score.go +++ b/src/utils/score.go @@ -8,6 +8,7 @@ import ( "pluja.dev/kycnot.me/database" "pluja.dev/kycnot.me/ent" + "pluja.dev/kycnot.me/ent/schema" ) func ComputeScore(s *ent.Service) int { @@ -41,6 +42,9 @@ func ComputeScore(s *ent.Service) int { } // Tos Highlights Penalty + if s.TosHighlights == nil { + s.TosHighlights = &[]schema.TosHighlight{} + } nTosH := len(*s.TosHighlights) nTosPenalty := float64(nTosH) * bonusMedium // Each 2 TOS highlights, decrease the score by 1 if nTosPenalty > maxTosPenalty {