Przeglądaj źródła

organization: limit showing at most 12 members in profile page (#6254)

ᴜɴᴋɴᴡᴏɴ 4 lat temu
rodzic
commit
f3993b9cdb

+ 1 - 0
CHANGELOG.md

@@ -17,6 +17,7 @@ All notable changes to Gogs are documented in this file.
 
 ### Changed
 
+- The organization profile page has changed to display at most 12 members. [#5506](https://github.com/gogs/gogs/issues/5506)
 - The required Go version to compile source code changed to 1.14.
 - All assets are now embedded into binary and served from memory by default. Set `[server] LOAD_ASSETS_FROM_DISK = true` to load them from disk. [#5920](https://github.com/gogs/gogs/pull/5920)
 - Application and Go versions are removed from page footer and only show in the admin dashboard.

+ 1 - 1
internal/db/issue.go

@@ -1173,7 +1173,7 @@ func updateIssueMentions(e Engine, issueID int64, mentions []string) error {
 		}
 
 		memberIDs := make([]int64, 0, user.NumMembers)
-		orgUsers, err := getOrgUsersByOrgID(e, user.ID)
+		orgUsers, err := getOrgUsersByOrgID(e, user.ID, 0)
 		if err != nil {
 			return fmt.Errorf("getOrgUsersByOrgID [%d]: %v", user.ID, err)
 		}

+ 11 - 6
internal/db/org.go

@@ -64,8 +64,8 @@ func (org *User) TeamsHaveAccessToRepo(repoID int64, mode AccessMode) ([]*Team,
 }
 
 // GetMembers returns all members of organization.
-func (org *User) GetMembers() error {
-	ous, err := GetOrgUsersByOrgID(org.ID)
+func (org *User) GetMembers(limit int) error {
+	ous, err := GetOrgUsersByOrgID(org.ID, limit)
 	if err != nil {
 		return err
 	}
@@ -315,14 +315,19 @@ func GetOrgIDsByUserID(userID int64, showPrivate bool) ([]int64, error) {
 	return orgIDs, sess.Distinct("org_id").Find(&orgIDs)
 }
 
-func getOrgUsersByOrgID(e Engine, orgID int64) ([]*OrgUser, error) {
+func getOrgUsersByOrgID(e Engine, orgID int64, limit int) ([]*OrgUser, error) {
 	orgUsers := make([]*OrgUser, 0, 10)
-	return orgUsers, e.Where("org_id=?", orgID).Find(&orgUsers)
+
+	sess := e.Where("org_id=?", orgID)
+	if limit > 0 {
+		sess = sess.Limit(limit)
+	}
+	return orgUsers, sess.Find(&orgUsers)
 }
 
 // GetOrgUsersByOrgID returns all organization-user relations by organization ID.
-func GetOrgUsersByOrgID(orgID int64) ([]*OrgUser, error) {
-	return getOrgUsersByOrgID(x, orgID)
+func GetOrgUsersByOrgID(orgID int64, limit int) ([]*OrgUser, error) {
+	return getOrgUsersByOrgID(x, orgID, limit)
 }
 
 // ChangeOrgUserStatus changes public or private membership status.

+ 2 - 2
internal/route/org/members.go

@@ -23,7 +23,7 @@ func Members(c *context.Context) {
 	c.Data["Title"] = org.FullName
 	c.Data["PageIsOrgMembers"] = true
 
-	if err := org.GetMembers(); err != nil {
+	if err := org.GetMembers(0); err != nil {
 		c.Error(err, "get members")
 		return
 	}
@@ -76,7 +76,7 @@ func MembersAction(c *context.Context) {
 
 	if err != nil {
 		log.Error("Action(%s): %v", c.Params(":action"), err)
-		c.JSONSuccess( map[string]interface{}{
+		c.JSONSuccess(map[string]interface{}{
 			"ok":  false,
 			"err": err.Error(),
 		})

+ 1 - 1
internal/route/user/home.go

@@ -403,7 +403,7 @@ func showOrgProfile(c *context.Context) {
 	}
 	c.Data["Page"] = paginater.New(int(count), conf.UI.User.RepoPagingNum, page, 5)
 
-	if err := org.GetMembers(); err != nil {
+	if err := org.GetMembers(12); err != nil {
 		c.Error(err, "get members")
 		return
 	}