Skip to content

Commit 45fc854

Browse files
committed
fix: wiped away some pretty important functionality, oops.
Signed-off-by: SamMayWork <[email protected]>
1 parent 0395957 commit 45fc854

File tree

2 files changed

+54
-15
lines changed

2 files changed

+54
-15
lines changed

internal/orchestrator/subscriptions.go

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -148,23 +148,31 @@ func (or *orchestrator) GetSubscriptionEventsHistorical(ctx context.Context, sub
148148
return nil, nil, err
149149
}
150150

151-
if startSequence == -1 {
152-
recordLimit := math.Min(float64(requestedFiltering.Limit), float64(config.GetInt(coreconfig.SubscriptionMaxHistoricalEventScanLength)))
153-
if endSequence-int(recordLimit) > 0 {
154-
startSequence = endSequence - int(recordLimit)
155-
} else {
156-
startSequence = 0
151+
var unfilteredEvents []*core.EnrichedEvent
152+
if startSequence == -1 && endSequence == -1 {
153+
unfilteredEvents, _, err = or.GetEventsWithReferences(ctx, filter)
154+
if err != nil {
155+
return nil, nil, err
156+
}
157+
} else {
158+
if startSequence == -1 {
159+
recordLimit := math.Min(float64(requestedFiltering.Limit), float64(config.GetInt(coreconfig.SubscriptionMaxHistoricalEventScanLength)))
160+
if endSequence-int(recordLimit) > 0 {
161+
startSequence = endSequence - int(recordLimit)
162+
} else {
163+
startSequence = 0
164+
}
157165
}
158-
}
159166

160-
if endSequence == -1 {
161-
// This blind assertion is safe since the DB won't blow up, it'll just return nothing
162-
endSequence = startSequence + 1000
163-
}
167+
if endSequence == -1 {
168+
// This blind assertion is safe since the DB won't blow up, it'll just return nothing
169+
endSequence = startSequence + 1000
170+
}
164171

165-
unfilteredEvents, _, err := or.GetEventsWithReferencesInSequenceRange(ctx, filter, startSequence, endSequence)
166-
if err != nil {
167-
return nil, nil, err
172+
unfilteredEvents, _, err = or.GetEventsWithReferencesInSequenceRange(ctx, filter, startSequence, endSequence)
173+
if err != nil {
174+
return nil, nil, err
175+
}
168176
}
169177

170178
filteredEvents, err := or.events.FilterHistoricalEventsOnSubscription(ctx, unfilteredEvents, subscription)

internal/orchestrator/subscriptions_test.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,6 @@ func TestGetHistoricalEventsForSubscriptionGettingHistoricalEventsThrows(t *test
477477

478478
baseEvents, _ := generateFakeEvents(20)
479479

480-
481480
or.mdi.On("GetEventsInSequenceRange", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(baseEvents, nil, nil)
482481
or.mem.On("EnrichEvents", mock.Anything, mock.Anything).Return([]*core.EnrichedEvent{}, nil)
483482
or.mem.On("FilterHistoricalEventsOnSubscription", mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("KERRR-BOOM!"))
@@ -582,3 +581,35 @@ func TestGetHistoricalEventsForSubscriptionStartSequenceNotProvided(t *testing.T
582581
assert.Equal(t, 1000, len(retEvents))
583582
}
584583

584+
func TestGetHistoricalEventsForSubscriptionNoStartOrEndSequence(t *testing.T) {
585+
or := newTestOrchestrator()
586+
defer or.cleanup(t)
587+
588+
fb := database.SubscriptionQueryFactory.NewFilter(context.Background())
589+
filter := fb.And()
590+
filter.Limit(1000)
591+
592+
baseEvents, enrichedEvents := generateFakeEvents(1000)
593+
594+
or.mdi.On("GetEvents", mock.Anything, mock.Anything, mock.Anything).Return(baseEvents, nil, nil)
595+
or.mem.On("EnrichEvents", mock.Anything, mock.Anything).Return(enrichedEvents, nil)
596+
or.mem.On("FilterHistoricalEventsOnSubscription", mock.Anything, mock.Anything, mock.Anything).Return(enrichedEvents, nil)
597+
598+
retEvents, _, err := or.GetSubscriptionEventsHistorical(context.Background(), &core.Subscription{}, filter, -1, -1)
599+
assert.Equal(t, err, nil)
600+
assert.Equal(t, 1000, len(retEvents))
601+
}
602+
603+
func TestGetHistoricalEventsForSubscriptionNoStartOrEndSequenceFails(t *testing.T) {
604+
or := newTestOrchestrator()
605+
defer or.cleanup(t)
606+
607+
fb := database.SubscriptionQueryFactory.NewFilter(context.Background())
608+
filter := fb.And()
609+
filter.Limit(1000)
610+
611+
or.mdi.On("GetEvents", mock.Anything, mock.Anything, mock.Anything).Return(nil, nil, fmt.Errorf("boom!"))
612+
613+
_, _, err := or.GetSubscriptionEventsHistorical(context.Background(), &core.Subscription{}, filter, -1, -1)
614+
assert.NotNil(t, err)
615+
}

0 commit comments

Comments
 (0)