1
0

fix(typesense): do not use modified opts for db fallback search

This commit is contained in:
kolaente 2024-07-11 12:52:09 +02:00
parent 7f27cee6a3
commit 8711f7a935
No known key found for this signature in database
GPG Key ID: F40E70337AB24C9B
3 changed files with 10 additions and 2 deletions

2
go.mod
View File

@ -116,6 +116,8 @@ require (
github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect
github.com/huandu/go-clone v1.6.0 // indirect
github.com/huandu/go-clone/generic v1.7.2 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect github.com/json-iterator/go v1.1.12 // indirect

5
go.sum
View File

@ -197,6 +197,11 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T
github.com/hhsnopek/etag v0.0.0-20171206181245-aea95f647346 h1:Odeq5rB6OZSkib5gqTG+EM1iF0bUVjYYd33XB1ULv00= github.com/hhsnopek/etag v0.0.0-20171206181245-aea95f647346 h1:Odeq5rB6OZSkib5gqTG+EM1iF0bUVjYYd33XB1ULv00=
github.com/hhsnopek/etag v0.0.0-20171206181245-aea95f647346/go.mod h1:4ggHM2qnyyZjenBb7RpwVzIj+JMsu9kHCVxMjB30hGs= github.com/hhsnopek/etag v0.0.0-20171206181245-aea95f647346/go.mod h1:4ggHM2qnyyZjenBb7RpwVzIj+JMsu9kHCVxMjB30hGs=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huandu/go-assert v1.1.5/go.mod h1:yOLvuqZwmcHIC5rIzrBhT7D3Q9c3GFnd0JrPVhn/06U=
github.com/huandu/go-clone v1.6.0 h1:HMo5uvg4wgfiy5FoGOqlFLQED/VGRm2D9Pi8g1FXPGc=
github.com/huandu/go-clone v1.6.0/go.mod h1:ReGivhG6op3GYr+UY3lS6mxjKp7MIGTknuU5TbTVaXE=
github.com/huandu/go-clone/generic v1.7.2 h1:47pQphxs1Xc9cVADjOHN+Bm5D0hNagwH9UXErbxgVKA=
github.com/huandu/go-clone/generic v1.7.2/go.mod h1:xgd9ZebcMsBWWcBx5mVMCoqMX24gLWr5lQicr+nVXNs=
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI= github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/ianlancetaylor/demangle v0.0.0-20220319035150-800ac71e25c2/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w= github.com/ianlancetaylor/demangle v0.0.0-20220319035150-800ac71e25c2/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w=

View File

@ -18,6 +18,7 @@ package models
import ( import (
"errors" "errors"
clone "github.com/huandu/go-clone/generic"
"math" "math"
"regexp" "regexp"
"sort" "sort"
@ -303,14 +304,14 @@ func getRawTasksForProjects(s *xorm.Session, projects []*Project, a web.Auth, op
var tsSearcher taskSearcher = &typesenseTaskSearcher{ var tsSearcher taskSearcher = &typesenseTaskSearcher{
s: s, s: s,
} }
origOpts := *opts origOpts := clone.Clone(opts)
tasks, totalItems, err = tsSearcher.Search(opts) tasks, totalItems, err = tsSearcher.Search(opts)
// It is possible that project views are not yet in Typesnse's index. This causes the query here to fail. // It is possible that project views are not yet in Typesnse's index. This causes the query here to fail.
// To avoid crashing everything, we fall back to the db search in that case. // To avoid crashing everything, we fall back to the db search in that case.
var tsErr = &typesense.HTTPError{} var tsErr = &typesense.HTTPError{}
if err != nil && errors.As(err, &tsErr) && tsErr.Status == 404 { if err != nil && errors.As(err, &tsErr) && tsErr.Status == 404 {
log.Warningf("Unable to fetch tasks from Typesense, error was '%v'. Falling back to db.", err) log.Warningf("Unable to fetch tasks from Typesense, error was '%v'. Falling back to db.", err)
tasks, totalItems, err = dbSearcher.Search(&origOpts) tasks, totalItems, err = dbSearcher.Search(origOpts)
} }
} else { } else {
tasks, totalItems, err = dbSearcher.Search(opts) tasks, totalItems, err = dbSearcher.Search(opts)