From d898b3cd8d9d4fc6e3ce0483ee55a63b15c0bf05 Mon Sep 17 00:00:00 2001 From: Frederick Robinson Date: Mon, 25 Dec 2023 13:54:52 -0800 Subject: [PATCH] refactor(filters): checkMaxDownloads (#1285) * refactor * fix: comment --------- Co-authored-by: ze0s <43699394+zze0s@users.noreply.github.com> --- internal/domain/filter.go | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/internal/domain/filter.go b/internal/domain/filter.go index b6eb7f0..fcec851 100644 --- a/internal/domain/filter.go +++ b/internal/domain/filter.go @@ -261,8 +261,8 @@ func (f *Filter) Validate() error { } 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 } @@ -514,37 +514,26 @@ func (f *Filter) CheckFilter(r *Release) ([]string, bool) { 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"