Add pagination for dashboard and user activity feeds (#22937)

Previously only the last few activities where available. This works for
all activity and for activity on a date chosen on the heatmap.
This commit is contained in:
Brecht Van Lommel 2023-02-24 22:15:10 +01:00 committed by GitHub
parent 740a5ecdd9
commit f4920c9c7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 81 additions and 32 deletions

View file

@ -380,14 +380,14 @@ type GetFeedsOptions struct {
}
// GetFeeds returns actions according to the provided options
func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, error) {
func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, int64, error) {
if opts.RequestedUser == nil && opts.RequestedTeam == nil && opts.RequestedRepo == nil {
return nil, fmt.Errorf("need at least one of these filters: RequestedUser, RequestedTeam, RequestedRepo")
return nil, 0, fmt.Errorf("need at least one of these filters: RequestedUser, RequestedTeam, RequestedRepo")
}
cond, err := activityQueryCondition(opts)
if err != nil {
return nil, err
return nil, 0, err
}
sess := db.GetEngine(ctx).Where(cond).
@ -398,16 +398,16 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, error) {
sess = db.SetSessionPagination(sess, &opts)
actions := make([]*Action, 0, opts.PageSize)
if err := sess.Desc("`action`.created_unix").Find(&actions); err != nil {
return nil, fmt.Errorf("Find: %w", err)
count, err := sess.Desc("`action`.created_unix").FindAndCount(&actions)
if err != nil {
return nil, 0, fmt.Errorf("FindAndCount: %w", err)
}
if err := ActionList(actions).loadAttributes(ctx); err != nil {
return nil, fmt.Errorf("LoadAttributes: %w", err)
return nil, 0, fmt.Errorf("LoadAttributes: %w", err)
}
return actions, nil
return actions, count, nil
}
// ActivityReadable return whether doer can read activities of user