fix: fix cache issue with whitelisted domains

This commit is contained in:
pommee
2025-10-31 18:29:58 +01:00
parent 835a1c2fcd
commit fe204f914e

View File

@@ -18,12 +18,7 @@ func InitializeWhitelist(dbManager *database.DatabaseManager) (*Whitelist, error
Cache: map[string]bool{},
}
_, err := w.GetDomains()
if err != nil {
log.Error("Failed to initialize whitelist cache")
}
return w, err
return w, w.refreshCache()
}
func (w *Whitelist) AddDomain(domain string) error {
@@ -54,6 +49,23 @@ func (w *Whitelist) RemoveDomain(domain string) error {
return nil
}
func (w *Whitelist) refreshCache() error {
for k := range w.Cache {
delete(w.Cache, k)
}
domains, err := w.GetDomains()
if err != nil {
return fmt.Errorf("could not get whitelisted domains while refreshing cache, %v", err)
}
for domain := range domains {
w.Cache[domain] = true
}
return nil
}
func (w *Whitelist) GetDomains() (map[string]bool, error) {
var records []database.Whitelist
if err := w.DBManager.Conn.Find(&records).Error; err != nil {