all repos — searchix @ d4ec6e5beecd549114dafd0b7c3b4a9d910388fb

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

fix: remove rendering from search timeout restriction
Alan Pearce alan@alanpearce.eu
Fri, 21 Mar 2025 22:18:15 +0100
commit

d4ec6e5beecd549114dafd0b7c3b4a9d910388fb

parent

9c9aa6b408812248c9f8c29ecc3546ef64947ea8

1 files changed, 6 insertions(+), 5 deletions(-)

jump to
M internal/server/mux.gointernal/server/mux.go
@@ -93,9 +93,6 @@ return 				}
 			}
 
-			ctx, cancel := context.WithTimeout(r.Context(), searchTimeout)
-			defer cancel()
-
 			if r.URL.Query().Has("query") {
 				qs := r.URL.Query().Get("query")
 
@@ -114,7 +111,11 @@ pageSize = math.MaxInt 					}
 				}
 				page := pagination.New(pageNumber, pageSize)
+
+				ctx, cancel := context.WithTimeout(r.Context(), searchTimeout)
 				results, err := index.Search(ctx, source, qs, page.From, page.Size)
+				cancel()
+
 				if err != nil {
 					if err == context.DeadlineExceeded {
 						errorHandler(w, r, "Search timed out", http.StatusInternalServerError)
@@ -219,9 +220,9 @@ } 			importerSingular := importerType.Singular()
 
 			ctx, cancel := context.WithTimeout(r.Context(), searchTimeout)
-			defer cancel()
-
 			doc, err := index.GetDocument(ctx, source, r.PathValue("id"))
+			cancel()
+
 			if err != nil {
 				errorHandler(
 					w,