@@ -198,19 +198,87 @@ func (db *BoltDB) SetActionState(al *ActionLocator, state ActionState,
198
198
})
199
199
}
200
200
201
- // ListActionsFilterFn defines a function that can be used to determine if an
202
- // action should be included in a set of results or not. The reversed parameter
203
- // indicates if the actions are being traversed in reverse order or not.
204
- // The first return boolean indicates if the action should be included or not
205
- // and the second one indicates if the iteration should be stopped or not.
206
- type ListActionsFilterFn func (a * Action , reversed bool ) (bool , bool )
201
+ // ListActions returns a list of Actions. The query IndexOffset and MaxNum
202
+ // params can be used to control the number of actions returned.
203
+ // ListActionOptions may be used to filter on specific Action values. The return
204
+ // values are the list of actions, the last index and the total count (iff
205
+ // query.CountTotal is set).
206
+ func (db * BoltDB ) ListActions (ctx context.Context , query * ListActionsQuery ,
207
+ options ... ListActionOption ) ([]* Action , uint64 , uint64 , error ) {
208
+
209
+ opts := newListActionOptions ()
210
+ for _ , o := range options {
211
+ o (opts )
212
+ }
213
+
214
+ filterFn := func (a * Action , reversed bool ) (bool , bool ) {
215
+ timeStamp := a .AttemptedAt
216
+ if ! opts .endTime .IsZero () {
217
+ // If actions are being considered in order and the
218
+ // timestamp of this action exceeds the given end
219
+ // timestamp, then there is no need to continue
220
+ // traversing.
221
+ if ! reversed && timeStamp .After (opts .endTime ) {
222
+ return false , false
223
+ }
224
+
225
+ // If the actions are in reverse order and the timestamp
226
+ // comes after the end timestamp, then the actions is
227
+ // not included but the search can continue.
228
+ if reversed && timeStamp .After (opts .endTime ) {
229
+ return false , true
230
+ }
231
+ }
232
+
233
+ if ! opts .startTime .IsZero () {
234
+ // If actions are being considered in order and the
235
+ // timestamp of this action comes before the given start
236
+ // timestamp, then the action is not included but the
237
+ // search can continue.
238
+ if ! reversed && timeStamp .Before (opts .startTime ) {
239
+ return false , true
240
+ }
241
+
242
+ // If the actions are in reverse order and the timestamp
243
+ // comes before the start timestamp, then there is no
244
+ // need to continue traversing.
245
+ if reversed && timeStamp .Before (opts .startTime ) {
246
+ return false , false
247
+ }
248
+ }
249
+
250
+ if opts .featureName != "" && a .FeatureName != opts .featureName {
251
+ return false , true
252
+ }
253
+
254
+ if opts .actorName != "" && a .ActorName != opts .actorName {
255
+ return false , true
256
+ }
207
257
208
- // ListActions returns a list of Actions that pass the filterFn requirements.
209
- // The indexOffset and maxNum params can be used to control the number of
210
- // actions returned. The return values are the list of actions, the last index
211
- // and the total count (iff query.CountTotal is set).
212
- func (db * BoltDB ) ListActions (filterFn ListActionsFilterFn ,
213
- query * ListActionsQuery ) ([]* Action , uint64 , uint64 , error ) {
258
+ if opts .methodName != "" && a .RPCMethod != opts .methodName {
259
+ return false , true
260
+ }
261
+
262
+ if opts .state != ActionStateUnknown && a .State != opts .state {
263
+ return false , true
264
+ }
265
+
266
+ return true , true
267
+ }
268
+
269
+ if opts .sessionID != session .EmptyID {
270
+ return db .listSessionActions (
271
+ opts .sessionID , filterFn , query ,
272
+ )
273
+ }
274
+ if opts .groupID != session .EmptyID {
275
+ actions , err := db .listGroupActions (ctx , opts .groupID , filterFn )
276
+ if err != nil {
277
+ return nil , 0 , 0 , err
278
+ }
279
+
280
+ return actions , 0 , uint64 (len (actions )), nil
281
+ }
214
282
215
283
var (
216
284
actions []* Action
@@ -242,7 +310,6 @@ func (db *BoltDB) ListActions(filterFn ListActionsFilterFn,
242
310
if err != nil {
243
311
return nil , err
244
312
}
245
-
246
313
return getAction (actionsBucket , locator )
247
314
}
248
315
@@ -255,14 +322,20 @@ func (db *BoltDB) ListActions(filterFn ListActionsFilterFn,
255
322
if err != nil {
256
323
return nil , 0 , 0 , err
257
324
}
258
-
259
325
return actions , lastIndex , totalCount , nil
260
326
}
261
327
262
- // ListSessionActions returns a list of the given session's Actions that pass
328
+ // listActionsFilterFn defines a function that can be used to determine if an
329
+ // action should be included in a set of results or not. The reversed parameter
330
+ // indicates if the actions are being traversed in reverse order or not.
331
+ // The first return boolean indicates if the action should be included or not
332
+ // and the second one indicates if the iteration should be continued or not.
333
+ type listActionsFilterFn func (a * Action , reversed bool ) (bool , bool )
334
+
335
+ // listSessionActions returns a list of the given session's Actions that pass
263
336
// the filterFn requirements.
264
- func (db * BoltDB ) ListSessionActions (sessionID session.ID ,
265
- filterFn ListActionsFilterFn , query * ListActionsQuery ) ([]* Action ,
337
+ func (db * BoltDB ) listSessionActions (sessionID session.ID ,
338
+ filterFn listActionsFilterFn , query * ListActionsQuery ) ([]* Action ,
266
339
uint64 , uint64 , error ) {
267
340
268
341
var (
@@ -303,12 +376,12 @@ func (db *BoltDB) ListSessionActions(sessionID session.ID,
303
376
return actions , lastIndex , totalCount , nil
304
377
}
305
378
306
- // ListGroupActions returns a list of the given session group's Actions that
379
+ // listGroupActions returns a list of the given session group's Actions that
307
380
// pass the filterFn requirements.
308
381
//
309
382
// TODO: update to allow for pagination.
310
- func (db * BoltDB ) ListGroupActions (ctx context.Context , groupID session.ID ,
311
- filterFn ListActionsFilterFn ) ([]* Action , error ) {
383
+ func (db * BoltDB ) listGroupActions (ctx context.Context , groupID session.ID ,
384
+ filterFn listActionsFilterFn ) ([]* Action , error ) {
312
385
313
386
if filterFn == nil {
314
387
filterFn = func (a * Action , reversed bool ) (bool , bool ) {
0 commit comments