From e6185b13931f48a4c3aea83970a89d7235496ac7 Mon Sep 17 00:00:00 2001 From: Julien Voisin Date: Thu, 12 Dec 2024 03:43:14 +0000 Subject: [PATCH] refactor: use min/max instead of math.Min/math.Max This saves a couple of back'n'forth casts. --- internal/model/feed.go | 4 ++-- internal/reader/readability/readability.go | 5 ++--- internal/reader/readingtime/readingtime.go | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/internal/model/feed.go b/internal/model/feed.go index 9f1de1eb..1682b111 100644 --- a/internal/model/feed.go +++ b/internal/model/feed.go @@ -123,8 +123,8 @@ func (f *Feed) ScheduleNextCheck(weeklyCount int, refreshDelayInMinutes int) { intervalMinutes = config.Opts.SchedulerEntryFrequencyMaxInterval() } else { intervalMinutes = int(math.Round(float64(7*24*60) / float64(weeklyCount*config.Opts.SchedulerEntryFrequencyFactor()))) - intervalMinutes = int(math.Min(float64(intervalMinutes), float64(config.Opts.SchedulerEntryFrequencyMaxInterval()))) - intervalMinutes = int(math.Max(float64(intervalMinutes), float64(config.Opts.SchedulerEntryFrequencyMinInterval()))) + intervalMinutes = min(intervalMinutes, config.Opts.SchedulerEntryFrequencyMaxInterval()) + intervalMinutes = max(intervalMinutes, config.Opts.SchedulerEntryFrequencyMinInterval()) } } diff --git a/internal/reader/readability/readability.go b/internal/reader/readability/readability.go index 299211f5..18f30ded 100644 --- a/internal/reader/readability/readability.go +++ b/internal/reader/readability/readability.go @@ -8,7 +8,6 @@ import ( "fmt" "io" "log/slog" - "math" "regexp" "strings" @@ -108,7 +107,7 @@ func ExtractContent(page io.Reader) (baseURL string, extractedContent string, er // Things like preambles, content split by ads that we removed, etc. func getArticle(topCandidate *candidate, candidates candidateList) string { output := bytes.NewBufferString("
") - siblingScoreThreshold := float32(math.Max(10, float64(topCandidate.score*.2))) + siblingScoreThreshold := max(10, topCandidate.score*.2) topCandidate.selection.Siblings().Union(topCandidate.selection).Each(func(i int, s *goquery.Selection) { append := false @@ -223,7 +222,7 @@ func getCandidates(document *goquery.Document) candidateList { contentScore += float32(strings.Count(text, ",") + 1) // For every 100 characters in this paragraph, add another point. Up to 3 points. - contentScore += float32(math.Min(float64(int(len(text)/100.0)), 3)) + contentScore += float32(min(int(len(text)/100.0), 3)) candidates[parentNode].score += contentScore if grandParentNode != nil { diff --git a/internal/reader/readingtime/readingtime.go b/internal/reader/readingtime/readingtime.go index 0cfb2b22..9159ee71 100644 --- a/internal/reader/readingtime/readingtime.go +++ b/internal/reader/readingtime/readingtime.go @@ -19,7 +19,7 @@ func EstimateReadingTime(content string, defaultReadingSpeed, cjkReadingSpeed in sanitizedContent := sanitizer.StripTags(content) // Litterature on language detection says that around 100 signes is enough, we're safe here. - truncationPoint := int(math.Min(float64(len(sanitizedContent)), 250)) + truncationPoint := min(len(sanitizedContent), 250) // We're only interested in identifying Japanse/Chinese/Korean options := whatlanggo.Options{