refactor(filters): checkMaxDownloads (#1285)

* refactor

* fix: comment

---------

Co-authored-by: ze0s <43699394+zze0s@users.noreply.github.com>
This commit is contained in:
Frederick Robinson 2023-12-25 13:54:52 -08:00 committed by GitHub
parent c6122dbc41
commit d898b3cd8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -261,8 +261,8 @@ func (f *Filter) Validate() error {
} }
func (f *Filter) CheckFilter(r *Release) ([]string, bool) { func (f *Filter) CheckFilter(r *Release) ([]string, bool) {
// max downloads check. If reached return early // max downloads check. If reached return early so other filters can be checked as quick as possible.
if f.MaxDownloads > 0 && !f.checkMaxDownloads(f.MaxDownloads, f.MaxDownloadsUnit) { if f.MaxDownloads > 0 && !f.checkMaxDownloads() {
f.addRejectionF("max downloads (%d) this (%v) reached", f.MaxDownloads, f.MaxDownloadsUnit) f.addRejectionF("max downloads (%d) this (%v) reached", f.MaxDownloads, f.MaxDownloadsUnit)
return f.Rejections, false return f.Rejections, false
} }
@ -514,37 +514,26 @@ func (f *Filter) CheckFilter(r *Release) ([]string, bool) {
return nil, true return nil, true
} }
func (f *Filter) checkMaxDownloads(max int, perTimeUnit FilterMaxDownloadsUnit) bool { func (f Filter) checkMaxDownloads() bool {
if f.Downloads == nil { if f.Downloads == nil {
return false return false
} }
switch perTimeUnit { var count int
switch f.MaxDownloadsUnit {
case FilterMaxDownloadsHour: case FilterMaxDownloadsHour:
if f.Downloads.HourCount > 0 && f.Downloads.HourCount >= max { count = f.Downloads.HourCount
return false
}
case FilterMaxDownloadsDay: case FilterMaxDownloadsDay:
if f.Downloads.DayCount > 0 && f.Downloads.DayCount >= max { count = f.Downloads.DayCount
return false
}
case FilterMaxDownloadsWeek: case FilterMaxDownloadsWeek:
if f.Downloads.WeekCount > 0 && f.Downloads.WeekCount >= max { count = f.Downloads.WeekCount
return false
}
case FilterMaxDownloadsMonth: case FilterMaxDownloadsMonth:
if f.Downloads.MonthCount > 0 && f.Downloads.MonthCount >= max { count = f.Downloads.MonthCount
return false
}
case FilterMaxDownloadsEver: case FilterMaxDownloadsEver:
if f.Downloads.TotalCount > 0 && f.Downloads.TotalCount >= max { count = f.Downloads.TotalCount
return false
}
default:
return true
} }
return true return count < f.MaxDownloads
} }
// isPerfectFLAC Perfect is "CD FLAC Cue Log 100% Lossless or 24bit Lossless" // isPerfectFLAC Perfect is "CD FLAC Cue Log 100% Lossless or 24bit Lossless"