Skip to content

Commit 893069e

Browse files
author
mirkobrombin
committed
feat: load site configurations concurrently to improve performance
1 parent 67e3b3f commit 893069e

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

internal/config/config.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"path/filepath"
88
"runtime"
99
"strings"
10+
"sync"
1011
)
1112

1213
// customLogDir is used to override the default log directory, e.g. for testing.
@@ -87,19 +88,30 @@ func LoadAllConfigs() ([]SiteConfig, error) {
8788
}
8889

8990
var configs []SiteConfig
91+
var mu sync.Mutex
92+
var wg sync.WaitGroup
93+
9094
for _, file := range files {
9195
if filepath.Ext(file.Name()) == ".json" {
92-
conf, err := LoadConfig(filepath.Join(configDir, file.Name()))
93-
if err != nil {
94-
fmt.Printf("Error loading config %s: %v\n", file.Name(), err)
95-
continue
96-
}
97-
configs = append(configs, conf)
98-
99-
// Populate the global SiteConfigs map
100-
SiteConfigs[conf.Domain] = conf
96+
wg.Add(1)
97+
go func(fname string) {
98+
defer wg.Done()
99+
100+
conf, err := LoadConfig(filepath.Join(configDir, fname))
101+
if err != nil {
102+
fmt.Printf("Error loading config %s: %v\n", fname, err)
103+
return
104+
}
105+
106+
mu.Lock()
107+
configs = append(configs, conf)
108+
SiteConfigs[conf.Domain] = conf
109+
mu.Unlock()
110+
}(file.Name())
101111
}
102112
}
113+
114+
wg.Wait()
103115
return configs, nil
104116
}
105117

0 commit comments

Comments
 (0)