From 858f65ee5a5fa08473595559c85d25c4a7225dfe Mon Sep 17 00:00:00 2001 From: yusing Date: Thu, 24 Apr 2025 06:24:28 +0800 Subject: [PATCH] fix: update code for error handling changes, remove unused code --- internal/config/config.go | 1 + internal/notif/dispatcher.go | 2 +- internal/utils/functional/map.go | 27 --------------------------- 3 files changed, 2 insertions(+), 28 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 5cc3bef7..663c4d62 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -319,6 +319,7 @@ func (cfg *Config) loadRouteProviders(providers *config.Providers) gperr.Error { lenLongestName = len(k) } }) + results.EnableConcurrency() cfg.providers.RangeAllParallel(func(_ string, p *proxy.Provider) { if err := p.LoadRoutes(); err != nil { errs.Add(err.Subject(p.String())) diff --git a/internal/notif/dispatcher.go b/internal/notif/dispatcher.go index fd138e52..08f80c75 100644 --- a/internal/notif/dispatcher.go +++ b/internal/notif/dispatcher.go @@ -89,7 +89,7 @@ func (disp *Dispatcher) dispatch(msg *LogMessage) { task := disp.task.Subtask("dispatcher") defer task.Finish("notif dispatched") - errs := gperr.NewBuilder(dispatchErr) + errs := gperr.NewBuilderWithConcurrency(dispatchErr) disp.providers.RangeAllParallel(func(p Provider) { if err := notifyProvider(task.Context(), p, msg); err != nil { errs.Add(gperr.PrependSubject(p.GetName(), err)) diff --git a/internal/utils/functional/map.go b/internal/utils/functional/map.go index f6283718..1b7a169e 100644 --- a/internal/utils/functional/map.go +++ b/internal/utils/functional/map.go @@ -87,33 +87,6 @@ func (m Map[KT, VT]) CollectErrors(do func(k KT, v VT) error) []error { return errs } -// CollectErrors calls the given function for each key-value pair in the map, -// then returns a slice of errors collected. -func (m Map[KT, VT]) CollectErrorsParallel(do func(k KT, v VT) error) []error { - if m.Size() < minParallelSize { - return m.CollectErrors(do) - } - - var errs []error - var mu sync.Mutex - var wg sync.WaitGroup - - m.Range(func(k KT, v VT) bool { - wg.Add(1) - go func() { - if err := do(k, v); err != nil { - mu.Lock() - errs = append(errs, err) - mu.Unlock() - } - wg.Done() - }() - return true - }) - wg.Wait() - return errs -} - func (m Map[KT, VT]) Has(k KT) bool { _, ok := m.Load(k) return ok