1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-07-12 16:58:36 +00:00

refactor: use min/max instead of math.Min/math.Max

This saves a couple of back'n'forth casts.
This commit is contained in:
Julien Voisin 2024-12-12 03:43:14 +00:00 committed by GitHub
parent 1b0b8b9c42
commit e6185b1393
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 5 additions and 6 deletions

View file

@ -123,8 +123,8 @@ func (f *Feed) ScheduleNextCheck(weeklyCount int, refreshDelayInMinutes int) {
intervalMinutes = config.Opts.SchedulerEntryFrequencyMaxInterval() intervalMinutes = config.Opts.SchedulerEntryFrequencyMaxInterval()
} else { } else {
intervalMinutes = int(math.Round(float64(7*24*60) / float64(weeklyCount*config.Opts.SchedulerEntryFrequencyFactor()))) intervalMinutes = int(math.Round(float64(7*24*60) / float64(weeklyCount*config.Opts.SchedulerEntryFrequencyFactor())))
intervalMinutes = int(math.Min(float64(intervalMinutes), float64(config.Opts.SchedulerEntryFrequencyMaxInterval()))) intervalMinutes = min(intervalMinutes, config.Opts.SchedulerEntryFrequencyMaxInterval())
intervalMinutes = int(math.Max(float64(intervalMinutes), float64(config.Opts.SchedulerEntryFrequencyMinInterval()))) intervalMinutes = max(intervalMinutes, config.Opts.SchedulerEntryFrequencyMinInterval())
} }
} }

View file

@ -8,7 +8,6 @@ import (
"fmt" "fmt"
"io" "io"
"log/slog" "log/slog"
"math"
"regexp" "regexp"
"strings" "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. // Things like preambles, content split by ads that we removed, etc.
func getArticle(topCandidate *candidate, candidates candidateList) string { func getArticle(topCandidate *candidate, candidates candidateList) string {
output := bytes.NewBufferString("<div>") output := bytes.NewBufferString("<div>")
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) { topCandidate.selection.Siblings().Union(topCandidate.selection).Each(func(i int, s *goquery.Selection) {
append := false append := false
@ -223,7 +222,7 @@ func getCandidates(document *goquery.Document) candidateList {
contentScore += float32(strings.Count(text, ",") + 1) contentScore += float32(strings.Count(text, ",") + 1)
// For every 100 characters in this paragraph, add another point. Up to 3 points. // 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 candidates[parentNode].score += contentScore
if grandParentNode != nil { if grandParentNode != nil {

View file

@ -19,7 +19,7 @@ func EstimateReadingTime(content string, defaultReadingSpeed, cjkReadingSpeed in
sanitizedContent := sanitizer.StripTags(content) sanitizedContent := sanitizer.StripTags(content)
// Litterature on language detection says that around 100 signes is enough, we're safe here. // 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 // We're only interested in identifying Japanse/Chinese/Korean
options := whatlanggo.Options{ options := whatlanggo.Options{