@@ -198,19 +198,87 @@ func (db *BoltDB) SetActionState(al *ActionLocator, state ActionState,
198198 })
199199}
200200
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+ }
207257
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+ }
214282
215283 var (
216284 actions []* Action
@@ -242,7 +310,6 @@ func (db *BoltDB) ListActions(filterFn ListActionsFilterFn,
242310 if err != nil {
243311 return nil , err
244312 }
245-
246313 return getAction (actionsBucket , locator )
247314 }
248315
@@ -255,14 +322,20 @@ func (db *BoltDB) ListActions(filterFn ListActionsFilterFn,
255322 if err != nil {
256323 return nil , 0 , 0 , err
257324 }
258-
259325 return actions , lastIndex , totalCount , nil
260326}
261327
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
263336// 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 ,
266339 uint64 , uint64 , error ) {
267340
268341 var (
@@ -303,12 +376,12 @@ func (db *BoltDB) ListSessionActions(sessionID session.ID,
303376 return actions , lastIndex , totalCount , nil
304377}
305378
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
307380// pass the filterFn requirements.
308381//
309382// 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 ) {
312385
313386 if filterFn == nil {
314387 filterFn = func (a * Action , reversed bool ) (bool , bool ) {
0 commit comments