lib/config: Don't cache device map (fixes #6816) (#6817)

This commit is contained in:
Simon Frei 2020-07-07 23:44:49 +02:00 committed by GitHub
parent 493de9392a
commit 8d67235a75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -96,7 +96,6 @@ type wrapper struct {
evLogger events.Logger
waiter Waiter // Latest ongoing config change
deviceMap map[protocol.DeviceID]DeviceConfiguration
subs []Committer
mut sync.Mutex
@ -195,7 +194,6 @@ func (w *wrapper) replaceLocked(to Configuration) (Waiter, error) {
}
w.cfg = to
w.deviceMap = nil
w.waiter = w.notifyListeners(from.Copy(), to.Copy())
@ -226,13 +224,11 @@ func (w *wrapper) notifyListener(sub Committer, from, to Configuration) {
func (w *wrapper) Devices() map[protocol.DeviceID]DeviceConfiguration {
w.mut.Lock()
defer w.mut.Unlock()
if w.deviceMap == nil {
w.deviceMap = make(map[protocol.DeviceID]DeviceConfiguration, len(w.cfg.Devices))
deviceMap := make(map[protocol.DeviceID]DeviceConfiguration, len(w.cfg.Devices))
for _, dev := range w.cfg.Devices {
w.deviceMap[dev.DeviceID] = dev.Copy()
deviceMap[dev.DeviceID] = dev.Copy()
}
}
return w.deviceMap
return deviceMap
}
// SetDevices adds new devices to the configuration, or overwrites existing