fix(filtering): skip update check if last check was within 24 hours
- commit
- c5fba1e5ab90c5dd673f730dc749583f6dcb0319
- author
- bnema · · 2025-11-29 15:58 UTC
- parent
- 26bfc2b
- signature
- GPG Unverified
2B82207D370127A0The key is unknown
3 files · +13 -0
M internal/filtering/manager.go +1 -0
| @@ -48,6 +48,7 @@ type FilterStore interface { | |||
| 48 | 48 | GetCacheInfo() (bool, time.Time, error) | |
| 49 | 49 | GetSourceVersion(url string) string | |
| 50 | 50 | SetSourceVersion(url string, version string) error | |
| 51 | + | GetLastCheckTime() time.Time | |
| 51 | 52 | } | |
| 52 | 53 | ||
| 53 | 54 | // FilterCompiler defines the interface for filter compilation | |
| @@ -48,6 +48,7 @@ type FilterStore interface { | |||||
| 48 | GetCacheInfo() (bool, time.Time, error) | 48 | GetCacheInfo() (bool, time.Time, error) | ||
| 49 | GetSourceVersion(url string) string | 49 | GetSourceVersion(url string) string | ||
| 50 | SetSourceVersion(url string, version string) error | 50 | SetSourceVersion(url string, version string) error | ||
| 51 | + | GetLastCheckTime() time.Time | |||
| 51 | } | 52 | } | ||
| 52 | 53 | ||||
| 53 | // FilterCompiler defines the interface for filter compilation | 54 | // FilterCompiler defines the interface for filter compilation | ||
M internal/filtering/updater.go +7 -0
| @@ -67,6 +67,13 @@ func (fu *FilterUpdater) CheckAndUpdate(ctx context.Context) error { | |||
| 67 | 67 | fu.updateMutex.Lock() | |
| 68 | 68 | defer fu.updateMutex.Unlock() | |
| 69 | 69 | ||
| 70 | + | // Skip if we checked within the last 24 hours | |
| 71 | + | lastCheck := fu.manager.store.GetLastCheckTime() | |
| 72 | + | if !lastCheck.IsZero() && time.Since(lastCheck) < 24*time.Hour { | |
| 73 | + | logging.Info(fmt.Sprintf("[filtering] Skipping update check, last check was %v ago", time.Since(lastCheck).Round(time.Minute))) | |
| 74 | + | return nil | |
| 75 | + | } | |
| 76 | + | ||
| 70 | 77 | startTime := time.Now() | |
| 71 | 78 | logging.Info("[filtering] Starting filter list update check...") | |
| 72 | 79 | ||
| @@ -67,6 +67,13 @@ func (fu *FilterUpdater) CheckAndUpdate(ctx context.Context) error { | |||||
| 67 | fu.updateMutex.Lock() | 67 | fu.updateMutex.Lock() | ||
| 68 | defer fu.updateMutex.Unlock() | 68 | defer fu.updateMutex.Unlock() | ||
| 69 | 69 | ||||
| 70 | + | // Skip if we checked within the last 24 hours | |||
| 71 | + | lastCheck := fu.manager.store.GetLastCheckTime() | |||
| 72 | + | if !lastCheck.IsZero() && time.Since(lastCheck) < 24*time.Hour { | |||
| 73 | + | logging.Info(fmt.Sprintf("[filtering] Skipping update check, last check was %v ago", time.Since(lastCheck).Round(time.Minute))) | |||
| 74 | + | return nil | |||
| 75 | + | } | |||
| 76 | + | ||||
| 70 | startTime := time.Now() | 77 | startTime := time.Now() | ||
| 71 | logging.Info("[filtering] Starting filter list update check...") | 78 | logging.Info("[filtering] Starting filter list update check...") | ||
| 72 | 79 | ||||
M internal/filtering/updater_test.go +5 -0
| @@ -158,6 +158,7 @@ type mockFilterStore struct { | |||
| 158 | 158 | cachedFilters *CompiledFilters | |
| 159 | 159 | cacheExists bool | |
| 160 | 160 | cacheModTime time.Time | |
| 161 | + | lastCheckTime time.Time | |
| 161 | 162 | } | |
| 162 | 163 | ||
| 163 | 164 | func (m *mockFilterStore) LoadCached() (*CompiledFilters, error) { | |
| @@ -187,3 +188,7 @@ func (m *mockFilterStore) SetSourceVersion(url string, version string) error { | |||
| 187 | 188 | m.sourceVersions[url] = version | |
| 188 | 189 | return nil | |
| 189 | 190 | } | |
| 191 | + | ||
| 192 | + | func (m *mockFilterStore) GetLastCheckTime() time.Time { | |
| 193 | + | return m.lastCheckTime | |
| 194 | + | } | |
| @@ -158,6 +158,7 @@ type mockFilterStore struct { | |||||
| 158 | cachedFilters *CompiledFilters | 158 | cachedFilters *CompiledFilters | ||
| 159 | cacheExists bool | 159 | cacheExists bool | ||
| 160 | cacheModTime time.Time | 160 | cacheModTime time.Time | ||
| 161 | + | lastCheckTime time.Time | |||
| 161 | } | 162 | } | ||
| 162 | 163 | ||||
| 163 | func (m *mockFilterStore) LoadCached() (*CompiledFilters, error) { | 164 | func (m *mockFilterStore) LoadCached() (*CompiledFilters, error) { | ||
| @@ -187,3 +188,7 @@ func (m *mockFilterStore) SetSourceVersion(url string, version string) error { | |||||
| 187 | m.sourceVersions[url] = version | 188 | m.sourceVersions[url] = version | ||
| 188 | return nil | 189 | return nil | ||
| 189 | } | 190 | } | ||
| 191 | + | ||||
| 192 | + | func (m *mockFilterStore) GetLastCheckTime() time.Time { | |||
| 193 | + | return m.lastCheckTime | |||
| 194 | + | } | |||