Optimize user dashboard loading (#33686)
Fix #33582 Fix #31698 When a user login, the dashboard should load all feed belongs to him with no any conditions. The complicated conditions should be applied only for another user view this user's profile.
This commit is contained in:
parent
2cd2ae07a7
commit
76b7f95a27
2 changed files with 44 additions and 14 deletions
|
@ -454,6 +454,24 @@ func ActivityReadable(user, doer *user_model.User) bool {
|
||||||
doer != nil && (doer.IsAdmin || user.ID == doer.ID)
|
doer != nil && (doer.IsAdmin || user.ID == doer.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FeedDateCond(opts GetFeedsOptions) builder.Cond {
|
||||||
|
cond := builder.NewCond()
|
||||||
|
if opts.Date == "" {
|
||||||
|
return cond
|
||||||
|
}
|
||||||
|
|
||||||
|
dateLow, err := time.ParseInLocation("2006-01-02", opts.Date, setting.DefaultUILocation)
|
||||||
|
if err != nil {
|
||||||
|
log.Warn("Unable to parse %s, filter not applied: %v", opts.Date, err)
|
||||||
|
} else {
|
||||||
|
dateHigh := dateLow.Add(86399000000000) // 23h59m59s
|
||||||
|
|
||||||
|
cond = cond.And(builder.Gte{"`action`.created_unix": dateLow.Unix()})
|
||||||
|
cond = cond.And(builder.Lte{"`action`.created_unix": dateHigh.Unix()})
|
||||||
|
}
|
||||||
|
return cond
|
||||||
|
}
|
||||||
|
|
||||||
func ActivityQueryCondition(ctx context.Context, opts GetFeedsOptions) (builder.Cond, error) {
|
func ActivityQueryCondition(ctx context.Context, opts GetFeedsOptions) (builder.Cond, error) {
|
||||||
cond := builder.NewCond()
|
cond := builder.NewCond()
|
||||||
|
|
||||||
|
@ -534,17 +552,7 @@ func ActivityQueryCondition(ctx context.Context, opts GetFeedsOptions) (builder.
|
||||||
cond = cond.And(builder.Eq{"is_deleted": false})
|
cond = cond.And(builder.Eq{"is_deleted": false})
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.Date != "" {
|
cond = cond.And(FeedDateCond(opts))
|
||||||
dateLow, err := time.ParseInLocation("2006-01-02", opts.Date, setting.DefaultUILocation)
|
|
||||||
if err != nil {
|
|
||||||
log.Warn("Unable to parse %s, filter not applied: %v", opts.Date, err)
|
|
||||||
} else {
|
|
||||||
dateHigh := dateLow.Add(86399000000000) // 23h59m59s
|
|
||||||
|
|
||||||
cond = cond.And(builder.Gte{"`action`.created_unix": dateLow.Unix()})
|
|
||||||
cond = cond.And(builder.Lte{"`action`.created_unix": dateHigh.Unix()})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return cond, nil
|
return cond, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,10 +208,32 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, int64, err
|
||||||
return nil, 0, 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(ctx, opts)
|
var err error
|
||||||
|
var cond builder.Cond
|
||||||
|
// if the actor is the requested user or is an administrator, we can skip the ActivityQueryCondition
|
||||||
|
if opts.Actor != nil && opts.RequestedUser != nil && (opts.Actor.IsAdmin || opts.Actor.ID == opts.RequestedUser.ID) {
|
||||||
|
cond = builder.Eq{
|
||||||
|
"user_id": opts.RequestedUser.ID,
|
||||||
|
}.And(
|
||||||
|
FeedDateCond(opts),
|
||||||
|
)
|
||||||
|
|
||||||
|
if !opts.IncludeDeleted {
|
||||||
|
cond = cond.And(builder.Eq{"is_deleted": false})
|
||||||
|
}
|
||||||
|
|
||||||
|
if !opts.IncludePrivate {
|
||||||
|
cond = cond.And(builder.Eq{"is_private": false})
|
||||||
|
}
|
||||||
|
if opts.OnlyPerformedBy {
|
||||||
|
cond = cond.And(builder.Eq{"act_user_id": opts.RequestedUser.ID})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cond, err = ActivityQueryCondition(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
actions := make([]*Action, 0, opts.PageSize)
|
actions := make([]*Action, 0, opts.PageSize)
|
||||||
var count int64
|
var count int64
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue