From 4556e501da0c8012a1e0c4cfb7691f5fa9c4a22b Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 23 Jun 2022 17:49:28 +0800 Subject: [PATCH] batch: fix time range checking --- pkg/exchange/batch/time_range_query.go | 6 ++---- pkg/service/sync_task.go | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/pkg/exchange/batch/time_range_query.go b/pkg/exchange/batch/time_range_query.go index 03535951e..ec97ab459 100644 --- a/pkg/exchange/batch/time_range_query.go +++ b/pkg/exchange/batch/time_range_query.go @@ -94,10 +94,8 @@ func (q *AsyncTimeRangedBatchQuery) Query(ctx context.Context, ch interface{}, s item := listRef.Index(i) entryTime := q.T(item.Interface()) - if entryTime.Before(startTime) { - continue - } - if entryTime.After(endTime) { + // inclusive time selection + if startTime.After(entryTime) || endTime.Before(entryTime) { continue } diff --git a/pkg/service/sync_task.go b/pkg/service/sync_task.go index 0727e0a76..80b421208 100644 --- a/pkg/service/sync_task.go +++ b/pkg/service/sync_task.go @@ -70,7 +70,7 @@ func (sel SyncTask) execute(ctx context.Context, db *sqlx.DB, startTime time.Tim ids := buildIdMap(sel, recordSliceRef) - if err := sortRecords(sel, recordSliceRef); err != nil { + if err := sortRecordsAscending(sel, recordSliceRef); err != nil { return err } @@ -177,7 +177,7 @@ func lastRecordTime(sel SyncTask, recordSlice reflect.Value, defaultTime time.Ti return since } -func sortRecords(sel SyncTask, recordSlice reflect.Value) error { +func sortRecordsAscending(sel SyncTask, recordSlice reflect.Value) error { if sel.Time == nil { return errors.New("time field is not set, can not sort records") }