all repos — searchix @ 8a1972abb4b429bd62b47cb44e3219d722919faf

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

feat: make web search timeout configurable

Alan Pearce
commit

8a1972abb4b429bd62b47cb44e3219d722919faf

parent

0b2627ff5be310d394fe63063bdf67e22debe12d

4 files changed, 6 insertions(+), 4 deletions(-)

changed files
M defaults.tomldefaults.toml
@@ -19,6 +19,8 @@ # Content to add to HTML <head>. Can be used to override styling, add scripts, etc.
ExtraHeadHTML = '' # Whether to log incoming HTTP requests LogRequests = true +# Timeout for search requests +SearchTimeout = '1s' # Content-Security-Policy header to send with requests. Should only need changing if ExtraHeadHTML is used. [Web.ContentSecurityPolicy]
M internal/config/default.gointernal/config/default.go
@@ -47,7 +47,8 @@ ),
"x-content-type-options": "nosniff", "x-frame-options": "DENY", }, - LogRequests: true, + LogRequests: true, + SearchTimeout: Duration{1 * time.Second}, }, Importer: &Importer{ LowMemory: false,
M internal/config/structs.gointernal/config/structs.go
@@ -29,6 +29,7 @@ Environment string `comment:"Affects logging parameters. One of 'development' or 'production'"`
ExtraHeadHTML string `comment:"Content to add to HTML <head>. Can be used to override styling, add scripts, etc."` Headers map[string]string `comment:"Extra headers to send with HTTP requests"` LogRequests bool `comment:"Whether to log incoming HTTP requests"` + SearchTimeout Duration `comment:"Timeout for search requests"` } type Importer struct {
M internal/server/mux.gointernal/server/mux.go
@@ -13,7 +13,6 @@ "path"
"slices" "strconv" "strings" - "time" "alin.ovh/searchix/frontend" "alin.ovh/searchix/internal/components"
@@ -82,7 +81,6 @@
top := http.NewServeMux() mux := sentryhttp.NewServeMux() - const searchTimeout = 1 * time.Second createSearchHandler := func(importerType config.ImporterType) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { var err error
@@ -123,7 +121,7 @@ }
} page := pagination.New(pageNumber, pageSize) - ctx, cancel := context.WithTimeout(r.Context(), searchTimeout) + ctx, cancel := context.WithTimeout(r.Context(), cfg.Web.SearchTimeout.Duration) results, err := index.Search(ctx, source, qs, page.From, page.Size) cancel()