mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-04 18:52:56 +00:00
gr
This commit is contained in:
@@ -521,12 +521,13 @@ func doPrefetchCycle(client *http.Client, baseURL string) {
|
||||
// 1) Static public endpoints
|
||||
endpoints := map[string]string{
|
||||
"/settings": "settings.json",
|
||||
"/seo": "seo.json",
|
||||
"/articles?page=1&page_size=10&published=true": "articles.json",
|
||||
"/sponsors": "sponsors.json",
|
||||
"/events/upcoming": "events_upcoming.json",
|
||||
"/public/team-logo-overrides": "team_logo_overrides.json",
|
||||
"/competition-aliases": "competition_aliases.json",
|
||||
}
|
||||
}
|
||||
statuses = make([]epStatus, 0, len(endpoints))
|
||||
for path, file := range endpoints {
|
||||
url := baseURL + path
|
||||
@@ -595,14 +596,25 @@ func doPrefetchCycle(client *http.Client, baseURL string) {
|
||||
|
||||
// in-flight guard to avoid overlapping cycles
|
||||
var prefetchInFlight int32
|
||||
var prefetchPending int32
|
||||
|
||||
func doPrefetchCycleGuarded(client *http.Client, baseURL string) {
|
||||
if !atomic.CompareAndSwapInt32(&prefetchInFlight, 0, 1) {
|
||||
log.Printf("[prefetch] skip: previous cycle still running")
|
||||
return
|
||||
}
|
||||
defer atomic.StoreInt32(&prefetchInFlight, 0)
|
||||
doPrefetchCycle(client, baseURL)
|
||||
if !atomic.CompareAndSwapInt32(&prefetchInFlight, 0, 1) {
|
||||
// Mark a rerun so we don't lose triggers (e.g., from setup) while a cycle is running
|
||||
atomic.StoreInt32(&prefetchPending, 1)
|
||||
log.Printf("[prefetch] in-flight: marked pending rerun")
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
atomic.StoreInt32(&prefetchInFlight, 0)
|
||||
// If a trigger arrived during this run, execute one more cycle immediately
|
||||
if atomic.SwapInt32(&prefetchPending, 0) == 1 {
|
||||
// Small delay to allow DB/cache writes to settle
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
doPrefetchCycleGuarded(client, baseURL)
|
||||
}
|
||||
}()
|
||||
doPrefetchCycle(client, baseURL)
|
||||
}
|
||||
|
||||
func isDuringMatch(cacheDir string) bool {
|
||||
|
||||
Reference in New Issue
Block a user