From dae57540e31f707d4f375ea96486f05353cdd116 Mon Sep 17 00:00:00 2001 From: xuu Date: Mon, 24 Mar 2025 18:28:57 -0600 Subject: [PATCH] chore: refine checkTemp --- refresh-loop.go | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/refresh-loop.go b/refresh-loop.go index e1f0b99..3ecef61 100644 --- a/refresh-loop.go +++ b/refresh-loop.go @@ -19,6 +19,7 @@ import ( const ( TenYear = 3153600000 + OneMonth = OneDay * 30 OneDay = 86400 OneHour = 3600 TenMinutes = 600 @@ -218,14 +219,12 @@ func processorLoop(ctx context.Context, db db, fetch *pool[*Feed, *Response]) { func checkTemp(twts types.Twts) int { if len(twts) < 5 { - return OneDay + return 7*OneDay } - sort.Sort(sort.Reverse(twts)) + sort.Sort(twts) - now := time.Now() - - since_first := now.Sub(twts[0].Created()) - since_fifth := now.Sub(twts[4].Created()) + since_first := -time.Until(twts[0].Created()) + since_fifth := -time.Until(twts[4].Created()) if since_first < 2 * time.Hour || since_fifth < 8 * time.Hour { return TwoMinutes @@ -236,8 +235,24 @@ func checkTemp(twts types.Twts) int { } if since_first < 8 * time.Hour || since_fifth < 32 * time.Hour{ - return TenMinutes + return 2*TenMinutes } - return OneDay + if since_first < 16 * time.Hour || since_fifth < 64 * time.Hour{ + return 4*TenMinutes + } + + if since_first < 24 * time.Hour || since_fifth < 128 * time.Hour{ + return OneDay + } + + if since_first < 48 * time.Hour || since_fifth < 256 * time.Hour{ + return 2*OneDay + } + + if since_first < 96 * time.Hour || since_fifth < 512 * time.Hour{ + return 7*OneDay + } + + return OneMonth }