Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1f0b695

Browse files
committedJun 14, 2021
Improve performance of dashboard list orgs
1 parent 2b39357 commit 1f0b695

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed
 

‎models/org.go

+19
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,25 @@ func GetOrgsByUserID(userID int64, showAll bool) ([]*User, error) {
425425
return getOrgsByUserID(sess, userID, showAll)
426426
}
427427

428+
// QueryUserOrgIDs returns a condition to return user's organization id
429+
func QueryUserOrgIDs(uid int64) *builder.Builder {
430+
return builder.Select("team.org_id").
431+
From("team_user").InnerJoin("team", "team.id = team_user.team_id").
432+
Where(builder.Eq{"team_user.uid": uid})
433+
}
434+
435+
// SimpleOrg represents a simple orgnization with only needed columns
436+
type SimpleOrg = User
437+
438+
// GetUserOrgsList returns one user's all orgs list
439+
func GetUserOrgsList(uid int64) ([]*SimpleOrg, error) {
440+
var orgs = make([]*SimpleOrg, 0, 20)
441+
return orgs, x.Select("id, name, full_name, visibility, avatar, avatar_email, use_custom_avatar").
442+
Table("user").
443+
In("id", QueryUserOrgIDs(uid)).
444+
Find(&orgs)
445+
}
446+
428447
func getOwnedOrgsByUserID(sess *xorm.Session, userID int64) ([]*User, error) {
429448
orgs := make([]*User, 0, 10)
430449
return orgs, sess.

‎routers/web/user/home.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ func getDashboardContextUser(ctx *context.Context) *models.User {
4949
}
5050
ctx.Data["ContextUser"] = ctxUser
5151

52-
if err := ctx.User.GetOrganizations(&models.SearchOrganizationsOptions{All: true}); err != nil {
52+
orgs, err := models.GetUserOrgsList(ctx.User.ID)
53+
if err != nil {
5354
ctx.ServerError("GetOrganizations", err)
5455
return nil
5556
}
56-
ctx.Data["Orgs"] = ctx.User.Orgs
57+
ctx.Data["Orgs"] = orgs
5758

5859
return ctxUser
5960
}

0 commit comments

Comments
 (0)
Please sign in to comment.