pkg/search: address staticcheck issues

Signed-off-by: Brad Fitzpatrick <brad@danga.com>
This commit is contained in:
Brad Fitzpatrick 2024-01-14 16:53:36 -08:00
parent b663eacb06
commit eba389eade
5 changed files with 34 additions and 36 deletions

View File

@ -39,13 +39,13 @@ import (
"perkeep.org/pkg/types/camtypes"
)
func (sh *Handler) serveDescribe(rw http.ResponseWriter, req *http.Request) {
func (h *Handler) serveDescribe(rw http.ResponseWriter, req *http.Request) {
defer httputil.RecoverJSON(rw, req)
var dr DescribeRequest
dr.fromHTTP(req)
ctx := context.TODO()
res, err := sh.Describe(ctx, &dr)
res, err := h.Describe(ctx, &dr)
if err != nil {
httputil.ServeJSONError(rw, err)
return
@ -57,16 +57,16 @@ const verboseDescribe = false
// Describe returns a response for the given describe request. It acquires RLock
// on the Handler's index.
func (sh *Handler) Describe(ctx context.Context, dr *DescribeRequest) (dres *DescribeResponse, err error) {
sh.index.RLock()
defer sh.index.RUnlock()
func (h *Handler) Describe(ctx context.Context, dr *DescribeRequest) (dres *DescribeResponse, err error) {
h.index.RLock()
defer h.index.RUnlock()
return sh.DescribeLocked(ctx, dr)
return h.DescribeLocked(ctx, dr)
}
// DescribeLocked returns a response for the given describe request. It is the
// caller's responsibility to lock the search handler's index.
func (sh *Handler) DescribeLocked(ctx context.Context, dr *DescribeRequest) (dres *DescribeResponse, err error) {
func (h *Handler) DescribeLocked(ctx context.Context, dr *DescribeRequest) (dres *DescribeResponse, err error) {
if verboseDescribe {
t0 := time.Now()
defer func() {
@ -78,7 +78,7 @@ func (sh *Handler) DescribeLocked(ctx context.Context, dr *DescribeRequest) (dre
log.Printf("Described %d blobs in %v", num, td)
}()
}
sh.initDescribeRequest(dr)
h.initDescribeRequest(dr)
if dr.BlobRef.Valid() {
dr.StartDescribe(ctx, dr.BlobRef, dr.depth())
}
@ -516,17 +516,17 @@ func (dp *DescribedPermanode) IsContainer() bool {
// NewDescribeRequest returns a new DescribeRequest holding the state
// of blobs and their summarized descriptions. Use DescribeBlob
// one or more times before calling Result.
func (sh *Handler) NewDescribeRequest() *DescribeRequest {
func (h *Handler) NewDescribeRequest() *DescribeRequest {
dr := new(DescribeRequest)
sh.initDescribeRequest(dr)
h.initDescribeRequest(dr)
return dr
}
func (sh *Handler) initDescribeRequest(req *DescribeRequest) {
func (h *Handler) initDescribeRequest(req *DescribeRequest) {
if req.sh != nil {
panic("already initialized")
}
req.sh = sh
req.sh = h
req.m = make(MetaMap)
req.errs = make(map[string]error)
req.wg = new(sync.WaitGroup)

View File

@ -34,15 +34,15 @@ func ExportSetExpandLocationHook(val bool) { expandLocationHook = val }
func ExportBufferedConst() int { return buffered }
func (s *SearchQuery) ExportPlannedQuery() *SearchQuery {
return s.plannedQuery(nil)
func (q *SearchQuery) ExportPlannedQuery() *SearchQuery {
return q.plannedQuery(nil)
}
var SortName = sortName
func (s *Handler) ExportGetPermanodeLocation(ctx context.Context, permaNode blob.Ref,
func (h *Handler) ExportGetPermanodeLocation(ctx context.Context, permaNode blob.Ref,
at time.Time) (camtypes.Location, error) {
return s.lh.PermanodeLocation(ctx, permaNode, at, s.owner)
return h.lh.PermanodeLocation(ctx, permaNode, at, h.owner)
}
func ExportBestByLocation(res *SearchResult, loc map[blob.Ref]camtypes.Location, limit int) {

View File

@ -189,19 +189,17 @@ func (p *parser) parseOrRHS(lhs *Constraint) (c *Constraint, err error) {
}
func (p *parser) parseAnd() (c *Constraint, err error) {
for {
c, err = p.parseOperand()
if err != nil {
return
}
switch p.peek().typ {
case tokenAnd:
p.next()
case tokenOr, tokenClose, tokenEOF:
return
}
return p.parseAndRHS(c)
c, err = p.parseOperand()
if err != nil {
return
}
switch p.peek().typ {
case tokenAnd:
p.next()
case tokenOr, tokenClose, tokenEOF:
return
}
return p.parseAndRHS(c)
}
func (p *parser) parseAndRHS(lhs *Constraint) (c *Constraint, err error) {
@ -322,7 +320,7 @@ func (p *parser) parseAtom() (*Constraint, error) {
}
t := faultToken()
err = newParseExpError(fmt.Sprintf("Unknown search predicate: %q", t.val), t)
log.Printf(err.Error())
log.Printf("parsing search expression atom: %v", err)
return nil, err
}

View File

@ -951,11 +951,11 @@ func evalSearchInput(in string) (*Constraint, error) {
}
// getNamed displays the search expression or constraint json for the requested alias.
func (sh *Handler) getNamed(ctx context.Context, name string) (string, error) {
if sh.fetcher == nil {
func (h *Handler) getNamed(ctx context.Context, name string) (string, error) {
if h.fetcher == nil {
return "", fmt.Errorf("GetNamed functionality not available")
}
sr, err := sh.Query(ctx, NamedSearch(name))
sr, err := h.Query(ctx, NamedSearch(name))
if err != nil {
return "", err
}
@ -970,7 +970,7 @@ func (sh *Handler) getNamed(ctx context.Context, name string) (string, error) {
return "", fmt.Errorf("Invalid blob ref: %s", substRefS)
}
reader, _, err := sh.fetcher.Fetch(ctx, br)
reader, _, err := h.fetcher.Fetch(ctx, br)
if err != nil {
return "", err
}

View File

@ -307,7 +307,7 @@ var upgrader = websocket.Upgrader{
// uses a default origin check policy
}
func (sh *Handler) serveWebSocket(rw http.ResponseWriter, req *http.Request) {
func (h *Handler) serveWebSocket(rw http.ResponseWriter, req *http.Request) {
ws, err := upgrader.Upgrade(rw, req, nil)
if _, ok := err.(websocket.HandshakeError); ok {
http.Error(rw, "Not a websocket handshake", http.StatusBadRequest)
@ -319,10 +319,10 @@ func (sh *Handler) serveWebSocket(rw http.ResponseWriter, req *http.Request) {
c := &wsConn{
ws: ws,
send: make(chan []byte, 256),
sh: sh,
sh: h,
queries: make(map[string]*watchedQuery),
}
sh.wsHub.register <- c
h.wsHub.register <- c
go c.writePump()
c.readPump()
}