all repos — searchix @ f459e84ecf7307fe2eeb7fbaa5b0c50613ec04f4

Search engine for NixOS, nix-darwin, home-manager and NUR users

perf: create search indexes in parallel with server startup
Alan Pearce alan@alanpearce.eu
Tue, 07 May 2024 21:40:19 +0200
commit

f459e84ecf7307fe2eeb7fbaa5b0c50613ec04f4

parent

212e5cf6621c99e46dbb37c860dab8938968bb19

1 files changed, 11 insertions(+), 8 deletions(-)

jump to
M internal/server/server.gointernal/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)