@@ -17,8 +17,8 @@ func (rec *subscriptionRecord) toModel() *scdmodels.Subscription {
1717 Version : scdmodels .NewOVNFromTime (rec .UpdatedAt , rec .ID .String ()),
1818 NotificationIndex : rec .NotificationIndex ,
1919 Manager : rec .Manager ,
20- StartTime : cloneTime (rec .StartTime ),
21- EndTime : cloneTime (rec .EndTime ),
20+ StartTime : timePtr (rec .StartTime ),
21+ EndTime : timePtr (rec .EndTime ),
2222 USSBaseURL : rec .USSBaseURL ,
2323 NotifyForOperationalIntents : rec .NotifyForOperationalIntents ,
2424 NotifyForConstraints : rec .NotifyForConstraints ,
@@ -44,11 +44,11 @@ func (r *repo) SearchSubscriptions(_ context.Context, v4d *dssmodels.Volume4D) (
4444 continue
4545 }
4646 // COALESCE(starts_at <= $3, true) with $3 = v4d.EndTime
47- if rec . StartTime != nil && v4d .EndTime != nil && rec .StartTime .After (* v4d .EndTime ) {
47+ if v4d .EndTime != nil && rec .StartTime .After (* v4d .EndTime ) {
4848 continue
4949 }
5050 // COALESCE(ends_at >= $2, true) with $2 = v4d.StartTime
51- if rec . EndTime != nil && v4d .StartTime != nil && rec .EndTime .Before (* v4d .StartTime ) {
51+ if v4d .StartTime != nil && rec .EndTime .Before (* v4d .StartTime ) {
5252 continue
5353 }
5454 out = append (out , rec .toModel ())
@@ -70,6 +70,9 @@ func (r *repo) GetSubscription(_ context.Context, id dssmodels.ID) (*scdmodels.S
7070
7171// UpsertSubscription implements scd.repos.Subscription.UpsertSubscription.
7272func (r * repo ) UpsertSubscription (ctx context.Context , s * scdmodels.Subscription ) (* scdmodels.Subscription , error ) {
73+ if err := requireExtentTimes (s .StartTime , s .EndTime ); err != nil {
74+ return nil , err
75+ }
7376 rec := & subscriptionRecord {
7477 ID : s .ID ,
7578 Manager : s .Manager ,
@@ -78,8 +81,8 @@ func (r *repo) UpsertSubscription(ctx context.Context, s *scdmodels.Subscription
7881 NotifyForOperationalIntents : s .NotifyForOperationalIntents ,
7982 NotifyForConstraints : s .NotifyForConstraints ,
8083 ImplicitSubscription : s .ImplicitSubscription ,
81- StartTime : cloneTime ( s .StartTime ) ,
82- EndTime : cloneTime ( s .EndTime ) ,
84+ StartTime : * s .StartTime ,
85+ EndTime : * s .EndTime ,
8386 Cells : cloneCells (s .Cells ),
8487 UpdatedAt : timestamp .NowFromContext (ctx ),
8588 }
@@ -134,14 +137,8 @@ func (r *repo) LockSubscriptionsOnCells(_ context.Context, _ s2.CellUnion, _ []d
134137func (r * repo ) ListExpiredSubscriptions (_ context.Context , threshold time.Time ) ([]* scdmodels.Subscription , error ) {
135138 var out []* scdmodels.Subscription
136139 for _ , rec := range r .state .Subscriptions {
137- // (ends_at IS NOT NULL AND ends_at <= threshold) OR (ends_at IS NULL AND updated_at <= threshold)
138- var expired bool
139- if rec .EndTime != nil {
140- expired = ! rec .EndTime .After (threshold )
141- } else {
142- expired = ! rec .UpdatedAt .After (threshold )
143- }
144- if ! expired {
140+ // ends_at <= threshold
141+ if rec .EndTime .After (threshold ) {
145142 continue
146143 }
147144 out = append (out , rec .toModel ())
0 commit comments