Skip to content

Commit

Permalink
fix: switch to better timing start and end
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksasiriski committed Jun 20, 2024
1 parent d583e2f commit 11e8412
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/router/routes/route_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"strconv"
"strings"
"time"

"github.com/hearchco/agent/src/cache"
"github.com/hearchco/agent/src/cli"
Expand All @@ -20,6 +21,9 @@ import (
)

func routeSearch(w http.ResponseWriter, r *http.Request, catsConf map[category.Name]config.Category, ttlConf config.TTL, db cache.DB, salt string) error {
// Capture start time.
startTime := time.Now()

// Parse form data (including query params).
if err := r.ParseForm(); err != nil {
// Server error.
Expand Down Expand Up @@ -150,7 +154,7 @@ func routeSearch(w http.ResponseWriter, r *http.Request, catsConf map[category.N
}

// Search for results.
scrapedRes, dur, err := search.Search(query, categoryName, opts, catsConf[categoryName])
scrapedRes, err := search.Search(query, categoryName, opts, catsConf[categoryName])
if err != nil {
// Server error.
werr := writeResponseJSON(w, http.StatusInternalServerError, ErrorResponse{
Expand Down Expand Up @@ -181,7 +185,7 @@ func routeSearch(w http.ResponseWriter, r *http.Request, catsConf map[category.N
// Create the response.
res := ResultsResponse{
Version: cli.VersionString(),
Duration: dur.Milliseconds(),
Duration: time.Since(startTime).Milliseconds(),
Results: outpusRes,
}

Expand Down
6 changes: 3 additions & 3 deletions src/search/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (
"github.com/hearchco/agent/src/utils/anonymize"
)

func Search(query string, category category.Name, opts options.Options, catConf config.Category) ([]result.Result, time.Duration, error) {
func Search(query string, category category.Name, opts options.Options, catConf config.Category) ([]result.Result, error) {
// Capture start time.
startTime := time.Now()

if err := validateParams(query, opts); err != nil {
return nil, time.Since(startTime), err
return nil, err
}

log.Debug().
Expand Down Expand Up @@ -109,5 +109,5 @@ func Search(query string, category category.Name, opts options.Options, catConf
Msg("Scraping finished")

// Return the results.
return results, time.Since(startTime), nil
return results, nil
}

0 comments on commit 11e8412

Please sign in to comment.