Skip to content

Commit

Permalink
Revert "Revert "fix (#718)""
Browse files Browse the repository at this point in the history
This reverts commit 440198f.
  • Loading branch information
nevgeny committed Sep 18, 2023
1 parent b2219b3 commit dc5ddd7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
4 changes: 4 additions & 0 deletions internal/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2533,6 +2533,9 @@ func (h *Handler) HandleGetPoint(w http.ResponseWriter, r *http.Request) {
respondJSON(w, nil, 0, 0, err, h.verbose, ai.user, sl)
return
}
if req.version == "" {
req.version = "2"
}
options := seriesRequestOptions{
debugQueries: true,
stat: sl,
Expand Down Expand Up @@ -2637,6 +2640,7 @@ func (h *Handler) handleGetPoint(ctx context.Context, ai accessInfo, opt seriesR
shiftTimestamp(req.from.Unix(), -1, toSec(oldestShift), h.location),
shiftTimestamp(req.to.Unix(), -1, toSec(oldestShift), h.location),
h.utcOffset,
req.expandToLODBoundary,
h.location,
)

Expand Down
42 changes: 24 additions & 18 deletions internal/api/point.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ func (pq pointQuery) isFast() bool {
return pq.fromSec+fastQueryTimeInterval >= pq.toSec
}

func selectQueryPoint(version string, preKeyFrom int64, preKeyOnly bool, resolution int, isUnique bool, isStringTop bool, now int64, from int64, to int64, utcOffset int64, location *time.Location) *pointQuery {
var lods []lodInfo
lods = selectQueryLODs(version, preKeyFrom, preKeyOnly, resolution, isUnique, isStringTop, now, from, to, utcOffset, resolution, widthLODRes, location)
lods = mergeForPointQuery(mergeLODs(lods), utcOffset, location)
func selectQueryPoint(version string, preKeyFrom int64, preKeyOnly bool, resolution int, isUnique bool, isStringTop bool, now int64, from int64, to int64, utcOffset int64, excessPoints bool, location *time.Location) *pointQuery {
lods := selectQueryLODs(version, preKeyFrom, preKeyOnly, resolution, isUnique, isStringTop, now, from, to, utcOffset, resolution, widthLODRes, location)
lod := mergeForPointQuery(from, to, mergeLODs(lods), utcOffset, excessPoints)
if len(lods) == 0 {
return nil
}
lod := lods[0]
return &pointQuery{
fromSec: lod.fromSec,
toSec: lod.toSec,
Expand All @@ -33,23 +31,31 @@ func selectQueryPoint(version string, preKeyFrom int64, preKeyOnly bool, resolut
}
}

func mergeForPointQuery(lods []lodInfo, utcOffset int64, location *time.Location) []lodInfo {
if len(lods) <= 1 {
return lods
func roundRangeForPoint(start int64, end int64, step int64, utcOffset int64, round bool) (int64, int64) {
rStart := roundTime(start, step, utcOffset)
rEnd := roundTime(end, step, utcOffset)
if end != start {
if rStart < start && !round {
rStart += step
}
if rEnd < end && round {
rEnd += step
}
}
return rStart, rEnd
}

func mergeForPointQuery(reqFrom, reqTo int64, lods []lodInfo, utcOffset int64, excessPoints bool) lodInfo {
hasPreKey := lods[0].hasPreKey
preKeyOnly := lods[0].preKeyOnly
from := lods[0].fromSec
to := lods[0].toSec
for _, lod := range lods {
hasPreKey = hasPreKey && lod.hasPreKey
to = lod.toSec
}
fromSec, toSec := roundRange(from, to, lods[0].stepSec, utcOffset, location)
lods = lods[:1]
lods[0].hasPreKey = hasPreKey
lods[0].preKeyOnly = preKeyOnly
lods[0].fromSec = fromSec
lods[0].toSec = toSec
return lods
fromSec, toSec := roundRangeForPoint(reqFrom, reqTo, lods[0].stepSec, utcOffset, excessPoints)
lod := lods[0]
lod.hasPreKey = hasPreKey
lod.preKeyOnly = preKeyOnly
lod.fromSec = fromSec
lod.toSec = toSec
return lod
}

0 comments on commit dc5ddd7

Please sign in to comment.