@@ -91,11 +91,11 @@ func (r *Repository) listResolvableAliases(ctx context.Context, permissions []pe
91
91
92
92
var args []any
93
93
var destinationIdClauses []string
94
+ var whereClause string
94
95
95
96
switch {
96
97
case allDescendants :
97
- // This matches all targets
98
- destinationIdClauses = append (destinationIdClauses , "destination_id in (select public_id from target)" )
98
+ whereClause = "destination_id is not null"
99
99
default :
100
100
// Add orgs with all permissions on children
101
101
if len (childAllScopes ) > 0 {
@@ -118,10 +118,9 @@ func (r *Repository) listResolvableAliases(ctx context.Context, permissions []pe
118
118
if len (destinationIdClauses ) == 0 && len (childAllScopes ) == 0 {
119
119
return nil , time.Time {}, errors .New (ctx , errors .InvalidParameter , op , "no target ids or scope ids provided" )
120
120
}
121
+ whereClause = fmt .Sprintf ("destination_id is not null and (%s)" , strings .Join (destinationIdClauses , " or " ))
121
122
}
122
123
123
- whereClause := fmt .Sprintf ("destination_id is not null and (%s)" , strings .Join (destinationIdClauses , " or " ))
124
-
125
124
if opts .withStartPageAfterItem != nil {
126
125
whereClause = fmt .Sprintf ("(create_time, public_id) < (@last_item_create_time, @last_item_id) and %s" , whereClause )
127
126
args = append (args ,
@@ -166,11 +165,11 @@ func (r *Repository) listResolvableAliasesRefresh(ctx context.Context, updatedAf
166
165
167
166
var args []any
168
167
var destinationIdClauses []string
168
+ var whereClause string
169
169
170
170
switch {
171
171
case allDescendants :
172
- // This matches all targets
173
- destinationIdClauses = append (destinationIdClauses , "destination_id in (select public_id from target)" )
172
+ whereClause = fmt .Sprintf ("update_time > @updated_after_time and destination_id is not null" )
174
173
default :
175
174
// Add orgs with all permissions on children
176
175
if len (childAllScopes ) > 0 {
@@ -193,10 +192,9 @@ func (r *Repository) listResolvableAliasesRefresh(ctx context.Context, updatedAf
193
192
if len (destinationIdClauses ) == 0 && len (childAllScopes ) == 0 {
194
193
return nil , time.Time {}, errors .New (ctx , errors .InvalidParameter , op , "no target ids or scope ids provided" )
195
194
}
195
+ whereClause = fmt .Sprintf ("update_time > @updated_after_time and destination_id is not null and (%s)" ,
196
+ strings .Join (destinationIdClauses , " or " ))
196
197
}
197
-
198
- whereClause := fmt .Sprintf ("update_time > @updated_after_time and destination_id is not null and (%s)" ,
199
- strings .Join (destinationIdClauses , " or " ))
200
198
args = append (args ,
201
199
sql .Named ("updated_after_time" , timestamp .New (updatedAfter )),
202
200
)
@@ -234,11 +232,10 @@ func (r *Repository) listRemovedResolvableAliasIds(ctx context.Context, since ti
234
232
235
233
var args []any
236
234
var destinationIdClauses []string
237
-
235
+ var whereClause string
238
236
switch {
239
237
case allDescendants :
240
- // This matches all targets
241
- destinationIdClauses = append (destinationIdClauses , "destination_id not in (select public_id from target)" )
238
+ whereClause = "update_time > @updated_after_time and destination_id is null"
242
239
default :
243
240
// Add orgs with all permissions on children
244
241
if len (childAllScopes ) > 0 {
@@ -261,10 +258,9 @@ func (r *Repository) listRemovedResolvableAliasIds(ctx context.Context, since ti
261
258
if len (destinationIdClauses ) == 0 && len (childAllScopes ) == 0 {
262
259
return nil , time.Time {}, errors .New (ctx , errors .InvalidParameter , op , "no target ids or scope ids provided" )
263
260
}
261
+ whereClause = fmt .Sprintf ("update_time > @updated_after_time and (destination_id is null or (%s))" ,
262
+ strings .Join (destinationIdClauses , " and " ))
264
263
}
265
-
266
- whereClause := fmt .Sprintf ("update_time > @updated_after_time and (destination_id is null or (%s))" ,
267
- strings .Join (destinationIdClauses , " and " ))
268
264
args = append (args ,
269
265
sql .Named ("updated_after_time" , timestamp .New (since )),
270
266
)
0 commit comments