diff options
author | Alan Pearce | 2024-05-07 21:40:19 +0200 |
---|---|---|
committer | Alan Pearce | 2024-05-07 21:40:19 +0200 |
commit | f459e84ecf7307fe2eeb7fbaa5b0c50613ec04f4 (patch) | |
tree | 235900bc6c11c0bbcdea6436461ed2a011ec5f58 | |
parent | 212e5cf6621c99e46dbb37c860dab8938968bb19 (diff) | |
download | searchix-f459e84ecf7307fe2eeb7fbaa5b0c50613ec04f4.tar.lz searchix-f459e84ecf7307fe2eeb7fbaa5b0c50613ec04f4.tar.zst searchix-f459e84ecf7307fe2eeb7fbaa5b0c50613ec04f4.zip |
perf: create search indexes in parallel with server startup
-rw-r--r-- | internal/server/server.go | 19 |
1 files changed, 11 insertions, 8 deletions
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() |