aboutsummaryrefslogtreecommitdiffstats
path: root/models/activities/action.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/activities/action.go')
-rw-r--r--models/activities/action.go54
1 files changed, 1 insertions, 53 deletions
diff --git a/models/activities/action.go b/models/activities/action.go
index 546d4340ae..65d95fbe66 100644
--- a/models/activities/action.go
+++ b/models/activities/action.go
@@ -448,65 +448,13 @@ type GetFeedsOptions struct {
Date string // the day we want activity for: YYYY-MM-DD
}
-// GetFeeds returns actions according to the provided options
-func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, int64, error) {
- if opts.RequestedUser == nil && opts.RequestedTeam == nil && opts.RequestedRepo == nil {
- return nil, 0, fmt.Errorf("need at least one of these filters: RequestedUser, RequestedTeam, RequestedRepo")
- }
-
- cond, err := activityQueryCondition(ctx, opts)
- if err != nil {
- return nil, 0, err
- }
-
- actions := make([]*Action, 0, opts.PageSize)
- var count int64
- opts.SetDefaultValues()
-
- if opts.Page < 10 { // TODO: why it's 10 but other values? It's an experience value.
- sess := db.GetEngine(ctx).Where(cond)
- sess = db.SetSessionPagination(sess, &opts)
-
- count, err = sess.Desc("`action`.created_unix").FindAndCount(&actions)
- if err != nil {
- return nil, 0, fmt.Errorf("FindAndCount: %w", err)
- }
- } else {
- // First, only query which IDs are necessary, and only then query all actions to speed up the overall query
- sess := db.GetEngine(ctx).Where(cond).Select("`action`.id")
- sess = db.SetSessionPagination(sess, &opts)
-
- actionIDs := make([]int64, 0, opts.PageSize)
- if err := sess.Table("action").Desc("`action`.created_unix").Find(&actionIDs); err != nil {
- return nil, 0, fmt.Errorf("Find(actionsIDs): %w", err)
- }
-
- count, err = db.GetEngine(ctx).Where(cond).
- Table("action").
- Cols("`action`.id").Count()
- if err != nil {
- return nil, 0, fmt.Errorf("Count: %w", err)
- }
-
- if err := db.GetEngine(ctx).In("`action`.id", actionIDs).Desc("`action`.created_unix").Find(&actions); err != nil {
- return nil, 0, fmt.Errorf("Find: %w", err)
- }
- }
-
- if err := ActionList(actions).LoadAttributes(ctx); err != nil {
- return nil, 0, fmt.Errorf("LoadAttributes: %w", err)
- }
-
- return actions, count, nil
-}
-
// ActivityReadable return whether doer can read activities of user
func ActivityReadable(user, doer *user_model.User) bool {
return !user.KeepActivityPrivate ||
doer != nil && (doer.IsAdmin || user.ID == doer.ID)
}
-func activityQueryCondition(ctx context.Context, opts GetFeedsOptions) (builder.Cond, error) {
+func ActivityQueryCondition(ctx context.Context, opts GetFeedsOptions) (builder.Cond, error) {
cond := builder.NewCond()
if opts.RequestedTeam != nil && opts.RequestedUser == nil {