batch: fix time range checking

This commit is contained in:
c9s 2022-06-23 17:49:28 +08:00
parent 8c1198de83
commit 4556e501da
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 4 additions and 6 deletions

View File

@ -94,10 +94,8 @@ func (q *AsyncTimeRangedBatchQuery) Query(ctx context.Context, ch interface{}, s
item := listRef.Index(i) item := listRef.Index(i)
entryTime := q.T(item.Interface()) entryTime := q.T(item.Interface())
if entryTime.Before(startTime) { // inclusive time selection
continue if startTime.After(entryTime) || endTime.Before(entryTime) {
}
if entryTime.After(endTime) {
continue continue
} }

View File

@ -70,7 +70,7 @@ func (sel SyncTask) execute(ctx context.Context, db *sqlx.DB, startTime time.Tim
ids := buildIdMap(sel, recordSliceRef) ids := buildIdMap(sel, recordSliceRef)
if err := sortRecords(sel, recordSliceRef); err != nil { if err := sortRecordsAscending(sel, recordSliceRef); err != nil {
return err return err
} }
@ -177,7 +177,7 @@ func lastRecordTime(sel SyncTask, recordSlice reflect.Value, defaultTime time.Ti
return since return since
} }
func sortRecords(sel SyncTask, recordSlice reflect.Value) error { func sortRecordsAscending(sel SyncTask, recordSlice reflect.Value) error {
if sel.Time == nil { if sel.Time == nil {
return errors.New("time field is not set, can not sort records") return errors.New("time field is not set, can not sort records")
} }