@@ -448,65 +448,13 @@ type GetFeedsOptions struct {
448448 Date string // the day we want activity for: YYYY-MM-DD
449449}
450450
451- // GetFeeds returns actions according to the provided options
452- func GetFeeds (ctx context.Context , opts GetFeedsOptions ) (ActionList , int64 , error ) {
453- if opts .RequestedUser == nil && opts .RequestedTeam == nil && opts .RequestedRepo == nil {
454- return nil , 0 , fmt .Errorf ("need at least one of these filters: RequestedUser, RequestedTeam, RequestedRepo" )
455- }
456-
457- cond , err := activityQueryCondition (ctx , opts )
458- if err != nil {
459- return nil , 0 , err
460- }
461-
462- actions := make ([]* Action , 0 , opts .PageSize )
463- var count int64
464- opts .SetDefaultValues ()
465-
466- if opts .Page < 10 { // TODO: why it's 10 but other values? It's an experience value.
467- sess := db .GetEngine (ctx ).Where (cond )
468- sess = db .SetSessionPagination (sess , & opts )
469-
470- count , err = sess .Desc ("`action`.created_unix" ).FindAndCount (& actions )
471- if err != nil {
472- return nil , 0 , fmt .Errorf ("FindAndCount: %w" , err )
473- }
474- } else {
475- // First, only query which IDs are necessary, and only then query all actions to speed up the overall query
476- sess := db .GetEngine (ctx ).Where (cond ).Select ("`action`.id" )
477- sess = db .SetSessionPagination (sess , & opts )
478-
479- actionIDs := make ([]int64 , 0 , opts .PageSize )
480- if err := sess .Table ("action" ).Desc ("`action`.created_unix" ).Find (& actionIDs ); err != nil {
481- return nil , 0 , fmt .Errorf ("Find(actionsIDs): %w" , err )
482- }
483-
484- count , err = db .GetEngine (ctx ).Where (cond ).
485- Table ("action" ).
486- Cols ("`action`.id" ).Count ()
487- if err != nil {
488- return nil , 0 , fmt .Errorf ("Count: %w" , err )
489- }
490-
491- if err := db .GetEngine (ctx ).In ("`action`.id" , actionIDs ).Desc ("`action`.created_unix" ).Find (& actions ); err != nil {
492- return nil , 0 , fmt .Errorf ("Find: %w" , err )
493- }
494- }
495-
496- if err := ActionList (actions ).LoadAttributes (ctx ); err != nil {
497- return nil , 0 , fmt .Errorf ("LoadAttributes: %w" , err )
498- }
499-
500- return actions , count , nil
501- }
502-
503451// ActivityReadable return whether doer can read activities of user
504452func ActivityReadable (user , doer * user_model.User ) bool {
505453 return ! user .KeepActivityPrivate ||
506454 doer != nil && (doer .IsAdmin || user .ID == doer .ID )
507455}
508456
509- func activityQueryCondition (ctx context.Context , opts GetFeedsOptions ) (builder.Cond , error ) {
457+ func ActivityQueryCondition (ctx context.Context , opts GetFeedsOptions ) (builder.Cond , error ) {
510458 cond := builder .NewCond ()
511459
512460 if opts .RequestedTeam != nil && opts .RequestedUser == nil {
0 commit comments