fixed 'fetched in X seconds seconds'
All checks were successful
Run Integration Tests / test (push) Successful in 26s
All checks were successful
Run Integration Tests / test (push) Successful in 26s
This commit is contained in:
parent
06f8604779
commit
6445be87a9
9 changed files with 38 additions and 18 deletions
18
common.go
18
common.go
|
@ -107,3 +107,21 @@ func GetIconPath() (string, string) {
|
|||
// Default paths
|
||||
return "/static/images/icon.svg", "/static/images/icon.png"
|
||||
}
|
||||
|
||||
// FormatElapsedTime formats elapsed time as a string,
|
||||
// using:
|
||||
// - "> 0.01 ms" if under 49µs
|
||||
// - "0.xx ms" if under 1ms
|
||||
// - "xxx ms" if under 300ms
|
||||
// - "x.xx seconds" otherwise
|
||||
func FormatElapsedTime(elapsed time.Duration) string {
|
||||
if elapsed < 49*time.Microsecond {
|
||||
return fmt.Sprintf("> 0.01 %s", Translate("milliseconds"))
|
||||
} else if elapsed < time.Millisecond {
|
||||
ms := float64(elapsed.Microseconds()) / 1000.0
|
||||
return fmt.Sprintf("%.2f %s", ms, Translate("milliseconds"))
|
||||
} else if elapsed < 300*time.Millisecond {
|
||||
return fmt.Sprintf("%d %s", elapsed.Milliseconds(), Translate("milliseconds"))
|
||||
}
|
||||
return fmt.Sprintf("%.2f %s", elapsed.Seconds(), Translate("seconds"))
|
||||
}
|
||||
|
|
2
files.go
2
files.go
|
@ -66,7 +66,7 @@ func handleFileSearch(w http.ResponseWriter, settings UserSettings, query string
|
|||
data := map[string]interface{}{
|
||||
"Results": combinedResults,
|
||||
"Query": query,
|
||||
"Fetched": fmt.Sprintf("%.2f %s", elapsedTime.Seconds(), Translate("seconds")), // Time for fetching results
|
||||
"Fetched": FormatElapsedTime(elapsedTime),
|
||||
"Category": "all",
|
||||
"Sort": "seed",
|
||||
"Page": page,
|
||||
|
|
|
@ -120,7 +120,7 @@ func handleForumsSearch(w http.ResponseWriter, settings UserSettings, query stri
|
|||
"Query": query,
|
||||
"Results": results,
|
||||
"Page": page,
|
||||
"Fetched": fmt.Sprintf("%.2f %s", elapsedTime.Seconds(), Translate("seconds")), // Time for fetching results
|
||||
"Fetched": FormatElapsedTime(elapsedTime),
|
||||
"HasPrevPage": page > 1,
|
||||
"HasNextPage": len(results) >= 25,
|
||||
"NoResults": len(results) == 0,
|
||||
|
|
|
@ -55,7 +55,7 @@ func handleImageSearch(w http.ResponseWriter, r *http.Request, settings UserSett
|
|||
data := map[string]interface{}{
|
||||
"Results": combinedResults,
|
||||
"Query": query,
|
||||
"Fetched": fmt.Sprintf("%.2f %s", elapsedTime.Seconds(), Translate("seconds")),
|
||||
"Fetched": FormatElapsedTime(elapsedTime),
|
||||
"Page": page,
|
||||
"HasPrevPage": page > 1,
|
||||
"HasNextPage": len(combinedResults) >= 50,
|
||||
|
|
|
@ -119,7 +119,13 @@ msgid "next"
|
|||
msgstr "Next"
|
||||
|
||||
msgid "fetched_in"
|
||||
msgstr "Fetched in %s seconds"
|
||||
msgstr "Fetched in %s"
|
||||
|
||||
msgid "seconds"
|
||||
msgstr "seconds"
|
||||
|
||||
msgid "milliseconds"
|
||||
msgstr "milliseconds"
|
||||
|
||||
msgid "sort_seeders"
|
||||
msgstr "Number of Seeders"
|
||||
|
|
15
map.go
15
map.go
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
type NominatimResponse struct {
|
||||
|
@ -59,7 +58,7 @@ func geocodeQuery(query string) (latitude, longitude string, found bool, err err
|
|||
|
||||
func handleMapSearch(w http.ResponseWriter, settings UserSettings, query string) {
|
||||
// Start measuring the time for geocoding the query
|
||||
startTime := time.Now()
|
||||
//startTime := time.Now()
|
||||
|
||||
// Geocode the query to get coordinates
|
||||
latitude, longitude, found, err := geocodeQuery(query)
|
||||
|
@ -70,15 +69,15 @@ func handleMapSearch(w http.ResponseWriter, settings UserSettings, query string)
|
|||
}
|
||||
|
||||
// Measure the elapsed time for geocoding
|
||||
elapsedTime := time.Since(startTime)
|
||||
//elapsed := time.Since(startTime)
|
||||
|
||||
// Prepare the data to pass to the template
|
||||
data := map[string]interface{}{
|
||||
"Query": query,
|
||||
"Latitude": latitude,
|
||||
"Longitude": longitude,
|
||||
"Found": found,
|
||||
"Fetched": fmt.Sprintf("%.2f %s", elapsedTime.Seconds(), Translate("seconds")),
|
||||
"Query": query,
|
||||
"Latitude": latitude,
|
||||
"Longitude": longitude,
|
||||
"Found": found,
|
||||
//"Fetched": FormatElapsedTime(elapsed), // not used in map tab
|
||||
"Theme": settings.Theme,
|
||||
"Safe": settings.SafeSearch,
|
||||
"IsThemeDark": settings.IsThemeDark,
|
||||
|
|
4
music.go
4
music.go
|
@ -2,7 +2,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
|
@ -59,7 +58,6 @@ func handleMusicSearch(w http.ResponseWriter, settings UserSettings, query strin
|
|||
go prefetchMusicPages(query, page)
|
||||
|
||||
elapsed := time.Since(start) // Calculate duration
|
||||
fetched := fmt.Sprintf("%.2f %s", elapsed.Seconds(), Translate("seconds"))
|
||||
|
||||
data := map[string]interface{}{
|
||||
"Results": results,
|
||||
|
@ -72,7 +70,7 @@ func handleMusicSearch(w http.ResponseWriter, settings UserSettings, query strin
|
|||
"Theme": settings.Theme,
|
||||
"IsThemeDark": settings.IsThemeDark,
|
||||
"Trans": Translate,
|
||||
"Fetched": fetched,
|
||||
"Fetched": FormatElapsedTime(elapsed),
|
||||
}
|
||||
|
||||
renderTemplate(w, "music.html", data)
|
||||
|
|
3
text.go
3
text.go
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
@ -51,7 +50,7 @@ func HandleTextSearch(w http.ResponseWriter, settings UserSettings, query string
|
|||
data := map[string]interface{}{
|
||||
"Results": combinedResults,
|
||||
"Query": query,
|
||||
"Fetched": fmt.Sprintf("%.2f %s", elapsedTime.Seconds(), Translate("seconds")), // Time for fetching results
|
||||
"Fetched": FormatElapsedTime(elapsedTime),
|
||||
"Page": page,
|
||||
"HasPrevPage": page > 1,
|
||||
"HasNextPage": len(combinedResults) >= 50,
|
||||
|
|
2
video.go
2
video.go
|
@ -157,7 +157,7 @@ func handleVideoSearch(w http.ResponseWriter, settings UserSettings, query strin
|
|||
data := map[string]interface{}{
|
||||
"Results": results,
|
||||
"Query": query,
|
||||
"Fetched": fmt.Sprintf("%.2f %s", elapsed.Seconds(), Translate("seconds")),
|
||||
"Fetched": FormatElapsedTime(elapsed),
|
||||
"Page": page,
|
||||
"HasPrevPage": page > 1,
|
||||
"HasNextPage": len(results) > 0,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue