sync: avoid adding the millisecond one to the start time

This commit is contained in:
c9s 2022-06-24 18:14:52 +08:00
parent cace7c8f97
commit a9bff7701c
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -34,10 +34,12 @@ type AsyncTimeRangedBatchQuery struct {
JumpIfEmpty time.Duration
}
func (q *AsyncTimeRangedBatchQuery) Query(ctx context.Context, ch interface{}, startTime, endTime time.Time) chan error {
func (q *AsyncTimeRangedBatchQuery) Query(ctx context.Context, ch interface{}, since, until time.Time) chan error {
errC := make(chan error, 1)
cRef := reflect.ValueOf(ch)
// cRef := reflect.MakeChan(reflect.TypeOf(q.Type), 100)
startTime := since
endTime := until
go func() {
defer cRef.Close()
@ -93,7 +95,7 @@ func (q *AsyncTimeRangedBatchQuery) Query(ctx context.Context, ch interface{}, s
for i := 0; i < listLen; i++ {
item := listRef.Index(i)
entryTime := q.T(item.Interface())
if entryTime.Before(startTime) || entryTime.After(endTime) {
if entryTime.Before(since) || entryTime.After(until) {
continue
}
@ -108,7 +110,7 @@ func (q *AsyncTimeRangedBatchQuery) Query(ctx context.Context, ch interface{}, s
cRef.Send(item)
sentAny = true
startTime = entryTime.Add(time.Millisecond)
startTime = entryTime
}
if !sentAny {