1

Display search time

This commit is contained in:
Alex Yatskov 2015-07-31 13:13:31 +09:00
parent 7ed040573a
commit 37e66d00ae
4 changed files with 12 additions and 4 deletions

View File

@ -32,6 +32,7 @@ import (
"net/http"
"runtime"
"strings"
"time"
"github.com/GaryBoone/GoStats/stats"
_ "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) {
startTime := time.Now()
var request jsonQueryRequest
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
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.ElapsedTime = time.Since(startTime).Nanoseconds()
js, err := json.Marshal(response)
if err != nil {
log.Fatal(err)

View File

@ -88,6 +88,7 @@
<div class="panel panel-default" style="display: none;" id="resultPanel">
<div class="panel-heading">
<big>Results (<span id="resultCount"></span>)</big>
<span class="pull-right text-muted" id="elapsedTime"></span>
</div>
<div class="panel-body">
<script id="template" type="text/x-handlers-template">

View File

@ -158,6 +158,7 @@
searchResultCnt += ' of ' + results.count;
}
$('#resultCount').text(searchResultCnt);
$('#elapsedTime').text(Math.round(results.elapsedTime / 1000000) + ' ms');
var template = Handlebars.compile($('#template').html());
$('#records').empty();

View File

@ -93,10 +93,11 @@ type jsonBracket struct {
}
type jsonQueryResponse struct {
Columns map[string]jsonColumn `json:"columns"`
Count int `json:"count"`
MinScore float64 `json:"minScore"`
Records []jsonRecord `json:"records"`
Columns map[string]jsonColumn `json:"columns"`
Count int `json:"count"`
MinScore float64 `json:"minScore"`
Records []jsonRecord `json:"records"`
ElapsedTime int64 `json:"elapsedTime"`
}
type jsonCategory struct {