perf: create search indexes in parallel with server startup
Alan Pearce alan@alanpearce.eu
Tue, 07 May 2024 21:40:19 +0200
1 files changed, 11 insertions(+), 8 deletions(-)
jump to
M internal/server/server.go → internal/server/server.go
@@ -80,15 +80,12 @@ "home-manager": "home-manager-options", "nixos": "nixos-options-nixos-unstable", } -func init() { +func makeIndex(source string, filename string) { var err error - - for source, filename := range sourceFileName { - index[source], err = search.New(filename) - if err != nil { - log.Fatalf("could not build search index, error: %#v", err) - } - + log.Printf("loading %s index", source) + index[source], err = search.New(filename) + if err != nil { + log.Fatalf("could not build search index, error: %#v", err) } } @@ -192,6 +189,12 @@ } }) mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("frontend/static")))) + + go func() { + for source, filename := range sourceFileName { + makeIndex(source, filename) + } + }() if runtimeConfig.LiveReload { applyDevModeOverrides(config)