feat: complete 2.0.7.12 platform overhaul

This commit is contained in:
2026-08-16 19:33:03 +08:00
parent 73555cd04c
commit c9fa6f7a88
159 changed files with 13243 additions and 2539 deletions
@@ -28,6 +28,8 @@ type publicSnapshotService struct {
entries map[string]publicSnapshotEntry
}
const maxPublicSnapshotEntries = 64
func newPublicSnapshotService(ttl time.Duration) *publicSnapshotService {
return &publicSnapshotService{ttl: ttl, entries: map[string]publicSnapshotEntry{}}
}
@@ -39,6 +41,22 @@ func (s *publicSnapshotService) Get(key string, build func(generatedAt time.Time
if entry, ok := s.entries[key]; ok && now.Before(entry.expiresAt) {
return entry.snapshot
}
for entryKey, entry := range s.entries {
if !now.Before(entry.expiresAt) {
delete(s.entries, entryKey)
}
}
if len(s.entries) >= maxPublicSnapshotEntries {
oldestKey := ""
var oldestExpiry time.Time
for entryKey, entry := range s.entries {
if oldestKey == "" || entry.expiresAt.Before(oldestExpiry) {
oldestKey = entryKey
oldestExpiry = entry.expiresAt
}
}
delete(s.entries, oldestKey)
}
payload := build(now)
data, err := json.Marshal(payload)