fix: remove rendering from search timeout restriction
Alan Pearce alan@alanpearce.eu
Fri, 21 Mar 2025 22:18:15 +0100
1 files changed, 6 insertions(+), 5 deletions(-)
jump to
M internal/server/mux.go → internal/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,