@@ -69,16 +69,9 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
6969 return
7070 }
7171
72- dateWhere := fmt .Sprintf (
73- "(Date >='%s' AND Date <= '%s' AND Time >= %d AND Time <= %d)" ,
74- time .Unix (fromTimestamp , 0 ).Format ("2006-01-02" ),
75- time .Unix (untilTimestamp , 0 ).Format ("2006-01-02" ),
76- fromTimestamp ,
77- untilTimestamp ,
78- )
79-
8072 var pathWhere string
8173
74+ maxStep := int32 (0 )
8275 if find .HasWildcard (target ) {
8376 // Search in small index table first
8477 treeWhere := find .MakeWhere (target , true )
@@ -105,6 +98,10 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
10598 if p == "" {
10699 continue
107100 }
101+ step := h .config .Rollup .Step (p , int32 (fromTimestamp ))
102+ if step > maxStep {
103+ maxStep = step
104+ }
108105
109106 if ! first {
110107 listBuf .Write ([]byte {',' })
@@ -131,8 +128,18 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
131128 // pathWhere = makeWhere(target, false)
132129 } else {
133130 pathWhere = fmt .Sprintf ("Path = '%s'" , target )
131+ maxStep = h .config .Rollup .Step (target , int32 (fromTimestamp ))
134132 }
135133
134+ until := untilTimestamp - untilTimestamp % int64 (maxStep ) + int64 (maxStep ) - 1
135+ dateWhere := fmt .Sprintf (
136+ "(Date >='%s' AND Date <= '%s' AND Time >= %d AND Time <= %d)" ,
137+ time .Unix (fromTimestamp , 0 ).Format ("2006-01-02" ),
138+ time .Unix (untilTimestamp , 0 ).Format ("2006-01-02" ),
139+ fromTimestamp ,
140+ until ,
141+ )
142+
136143 // @TODO: change format to RowBinary
137144 query := fmt .Sprintf (
138145 `
@@ -325,7 +332,7 @@ func (h *Handler) ReplyProtobuf(w http.ResponseWriter, r *http.Request, points [
325332
326333 var index int32
327334 // skip points before start
328- for index = 0 ; points [index ].Time < start ; index ++ {
335+ for index = 0 ; index < int32 ( len ( points )) && points [index ].Time < start ; index ++ {
329336 }
330337
331338 for i := int32 (0 ); i < count ; i ++ {
0 commit comments