Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(filters): checkMaxDownloads #1285

Merged
merged 3 commits into from
Dec 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 11 additions & 22 deletions internal/domain/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@
}

func (f *Filter) CheckFilter(r *Release) ([]string, bool) {
// max downloads check. If reached return early
if f.MaxDownloads > 0 && !f.checkMaxDownloads(f.MaxDownloads, f.MaxDownloadsUnit) {
// max downloads check. If reached return early so other filters can be checked as quick as possible.
if f.MaxDownloads > 0 && !f.checkMaxDownloads() {
f.addRejectionF("max downloads (%d) this (%v) reached", f.MaxDownloads, f.MaxDownloadsUnit)
return f.Rejections, false
}
Expand Down Expand Up @@ -514,37 +514,26 @@
return nil, true
}

func (f *Filter) checkMaxDownloads(max int, perTimeUnit FilterMaxDownloadsUnit) bool {
func (f Filter) checkMaxDownloads() bool {
if f.Downloads == nil {
return false
}

switch perTimeUnit {
var count int
switch f.MaxDownloadsUnit {
case FilterMaxDownloadsHour:
if f.Downloads.HourCount > 0 && f.Downloads.HourCount >= max {
return false
}
count = f.Downloads.HourCount
case FilterMaxDownloadsDay:
if f.Downloads.DayCount > 0 && f.Downloads.DayCount >= max {
return false
}
count = f.Downloads.DayCount
case FilterMaxDownloadsWeek:
if f.Downloads.WeekCount > 0 && f.Downloads.WeekCount >= max {
return false
}
count = f.Downloads.WeekCount
case FilterMaxDownloadsMonth:
if f.Downloads.MonthCount > 0 && f.Downloads.MonthCount >= max {
return false
}
count = f.Downloads.MonthCount
case FilterMaxDownloadsEver:
if f.Downloads.TotalCount > 0 && f.Downloads.TotalCount >= max {
return false
}
default:
return true
count = f.Downloads.TotalCount
}

return true
return count < f.MaxDownloads
}

// isPerfectFLAC Perfect is "CD FLAC Cue Log 100% Lossless or 24bit Lossless"
Expand Down Expand Up @@ -678,7 +667,7 @@
return false
}

max, err := strconv.ParseInt(minMax[1], 10, 32)

Check failure on line 670 in internal/domain/filter.go

View workflow job for this annotation

GitHub Actions / Nilaway Linter

error: Potential nil panic detected. Observed nil flow from source to dereference point:
if err != nil {
return false
}
Expand Down
Loading