feat: make web search timeout configurable
4 files changed, 6 insertions(+), 4 deletions(-)
M defaults.toml → defaults.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.go → internal/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.go → internal/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.go → internal/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()