about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--internal/server/server.go19
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()