summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-06-14 20:18:09 +0800
committerGitHub <noreply@github.com>2021-06-14 20:18:09 +0800
commit5d113bdd1905c73fb8071f420ae2d248202971f9 (patch)
treeada92c8b506c64218fa1340879117c5ea2c2309f /models
parent1295e750b4b8cec5476e7666bf9f8f3a02b39785 (diff)
downloadgitea-5d113bdd1905c73fb8071f420ae2d248202971f9.tar.gz
gitea-5d113bdd1905c73fb8071f420ae2d248202971f9.zip
Improve performance of dashboard list orgs (#16099)
* Improve performance of dashboard list orgs * Fix wrong error description * unexport queryUserOrgIDs method * SimpleOrg -> MinimalOrg * . Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'models')
-rw-r--r--models/org.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/models/org.go b/models/org.go
index 3474988efc..7f9e3cce5b 100644
--- a/models/org.go
+++ b/models/org.go
@@ -425,6 +425,25 @@ func GetOrgsByUserID(userID int64, showAll bool) ([]*User, error) {
return getOrgsByUserID(sess, userID, showAll)
}
+// queryUserOrgIDs returns a condition to return user's organization id
+func queryUserOrgIDs(uid int64) *builder.Builder {
+ return builder.Select("team.org_id").
+ From("team_user").InnerJoin("team", "team.id = team_user.team_id").
+ Where(builder.Eq{"team_user.uid": uid})
+}
+
+// MinimalOrg represents a simple orgnization with only needed columns
+type MinimalOrg = User
+
+// GetUserOrgsList returns one user's all orgs list
+func GetUserOrgsList(uid int64) ([]*MinimalOrg, error) {
+ var orgs = make([]*MinimalOrg, 0, 20)
+ return orgs, x.Select("id, name, full_name, visibility, avatar, avatar_email, use_custom_avatar").
+ Table("user").
+ In("id", queryUserOrgIDs(uid)).
+ Find(&orgs)
+}
+
func getOwnedOrgsByUserID(sess *xorm.Session, userID int64) ([]*User, error) {
orgs := make([]*User, 0, 10)
return orgs, sess.