diff --git a/querylog/qlog.go b/querylog/qlog.go index a0570011..55020612 100644 --- a/querylog/qlog.go +++ b/querylog/qlog.go @@ -231,6 +231,13 @@ func (l *queryLog) getData(params getDataParams) map[string]interface{} { // remove extra records entries = entries[(len(entries) - getDataLimit):] } + if len(entries) == getDataLimit { + // change the "oldest" value here. + // we cannot use the "oldest" we got from "searchFiles" anymore + // because after adding in-memory records and removing extra records + // the situation has changed + oldest = entries[len(entries)-1].Time + } // init the response object var data = []map[string]interface{}{} @@ -246,9 +253,6 @@ func (l *queryLog) getData(params getDataParams) map[string]interface{} { len(entries), total, params.OlderThan, time.Since(now)) var result = map[string]interface{}{} - if len(entries) == getDataLimit { - oldest = entries[0].Time - } result["oldest"] = "" if !oldest.IsZero() { result["oldest"] = oldest.Format(time.RFC3339Nano) diff --git a/querylog/querylog_search.go b/querylog/querylog_search.go index 236c1940..f9493af9 100644 --- a/querylog/querylog_search.go +++ b/querylog/querylog_search.go @@ -36,10 +36,16 @@ func (l *queryLog) searchFiles(params getDataParams) ([]*logEntry, time.Time, in err = r.SeekStart() } else { err = r.Seek(params.OlderThan.UnixNano()) + if err == nil { + // Read to the next record right away + // The one that was specified in the "oldest" param is not needed, + // we need only the one next to it + _, err = r.ReadNext() + } } if err != nil { - log.Error("Failed to Seek(): %v", err) + log.Debug("Cannot Seek() to %v: %v", params.OlderThan, err) return entries, oldest, 0 } @@ -54,12 +60,16 @@ func (l *queryLog) searchFiles(params getDataParams) ([]*logEntry, time.Time, in break } - if entry != nil { - entries = append(entries, entry) - } - oldestNano = ts total++ + + if entry != nil { + entries = append(entries, entry) + if len(entries) == getDataLimit { + // Do not read more than "getDataLimit" records at once + break + } + } } oldest = time.Unix(0, oldestNano)