From f459e84ecf7307fe2eeb7fbaa5b0c50613ec04f4 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Tue, 7 May 2024 21:40:19 +0200 Subject: perf: create search indexes in parallel with server startup --- internal/server/server.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'internal/server') diff --git a/internal/server/server.go b/internal/server/server.go index 3b85061..9649ad2 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -80,15 +80,12 @@ var sourceFileName = map[string]string{ "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) } } @@ -193,6 +190,12 @@ func New(runtimeConfig *Config) (*Server, error) { 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) liveReload := livereload.New() -- cgit 1.4.1