Skip to content

Commit

Permalink
Merge pull request #201 from spq/query_elapsed_time
Browse files Browse the repository at this point in the history
Display seconds a query took to run
  • Loading branch information
peace-maker authored Nov 22, 2024
2 parents affdad0 + d48bded commit 681d81f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/pkappa2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ func main() {
Stream *index.Stream
Tags []string
}
Elapsed int64
Offset uint
MoreResults bool
}{
Expand All @@ -543,6 +544,7 @@ func main() {
Tags []string
}{},
}
start := time.Now()
v := mgr.GetView()
defer v.Release()
hasMore, offset, err := v.SearchStreams(r.Context(), qq, func(c manager.StreamContext) error {
Expand All @@ -563,6 +565,7 @@ func main() {
http.Error(w, fmt.Sprintf("SearchStreams failed: %v", err), http.StatusInternalServerError)
return
}
response.Elapsed = time.Since(start).Microseconds()
response.MoreResults = hasMore
response.Offset = offset
w.Header().Set("Content-Type", "application/json")
Expand Down
1 change: 1 addition & 0 deletions web/src/apiClient.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export function isSearchResult(obj: unknown): obj is SearchResult {
typeof e === "string"
)
) &&
typeof typedObj["Elapsed"] === "number" &&
typeof typedObj["Offset"] === "number" &&
typeof typedObj["MoreResults"] === "boolean"
)
Expand Down
1 change: 1 addition & 0 deletions web/src/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export type Error = {
export type SearchResult = {
Debug: string[];
Results: Result[];
Elapsed: number;
Offset: number;
MoreResults: boolean;
};
Expand Down
6 changes: 6 additions & 0 deletions web/src/components/Results.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@
>Results might be outdated.</v-alert
>
<v-spacer />
<div v-if="streams.result">
<span class="text-caption">
Query took {{ (streams.result.Elapsed / 1_000_000).toFixed(6) }}s
</span>
</div>
<v-spacer />
<div
v-if="
!streams.running &&
Expand Down

0 comments on commit 681d81f

Please sign in to comment.