Display search time
This commit is contained in:
parent
7ed040573a
commit
37e66d00ae
@ -32,6 +32,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/GaryBoone/GoStats/stats"
|
"github.com/GaryBoone/GoStats/stats"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
@ -85,6 +86,8 @@ func prepareColumn(request jsonQueryRequest, entries, foundEntries records, feat
|
|||||||
}
|
}
|
||||||
|
|
||||||
func executeQuery(rw http.ResponseWriter, req *http.Request) {
|
func executeQuery(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
startTime := time.Now()
|
||||||
|
|
||||||
var request jsonQueryRequest
|
var request jsonQueryRequest
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||||
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||||
@ -139,6 +142,8 @@ func executeQuery(rw http.ResponseWriter, req *http.Request) {
|
|||||||
response.Records = append(response.Records, item)
|
response.Records = append(response.Records, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
response.ElapsedTime = time.Since(startTime).Nanoseconds()
|
||||||
|
|
||||||
js, err := json.Marshal(response)
|
js, err := json.Marshal(response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -88,6 +88,7 @@
|
|||||||
<div class="panel panel-default" style="display: none;" id="resultPanel">
|
<div class="panel panel-default" style="display: none;" id="resultPanel">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<big>Results (<span id="resultCount"></span>)</big>
|
<big>Results (<span id="resultCount"></span>)</big>
|
||||||
|
<span class="pull-right text-muted" id="elapsedTime"></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<script id="template" type="text/x-handlers-template">
|
<script id="template" type="text/x-handlers-template">
|
||||||
|
@ -158,6 +158,7 @@
|
|||||||
searchResultCnt += ' of ' + results.count;
|
searchResultCnt += ' of ' + results.count;
|
||||||
}
|
}
|
||||||
$('#resultCount').text(searchResultCnt);
|
$('#resultCount').text(searchResultCnt);
|
||||||
|
$('#elapsedTime').text(Math.round(results.elapsedTime / 1000000) + ' ms');
|
||||||
|
|
||||||
var template = Handlebars.compile($('#template').html());
|
var template = Handlebars.compile($('#template').html());
|
||||||
$('#records').empty();
|
$('#records').empty();
|
||||||
|
1
types.go
1
types.go
@ -97,6 +97,7 @@ type jsonQueryResponse struct {
|
|||||||
Count int `json:"count"`
|
Count int `json:"count"`
|
||||||
MinScore float64 `json:"minScore"`
|
MinScore float64 `json:"minScore"`
|
||||||
Records []jsonRecord `json:"records"`
|
Records []jsonRecord `json:"records"`
|
||||||
|
ElapsedTime int64 `json:"elapsedTime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type jsonCategory struct {
|
type jsonCategory struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user