From 827b70290afab0a947887548d15a6532d5f87afa Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Mon, 20 Jun 2022 17:38:39 +0800 Subject: [PATCH 1/5] Add order by for #6 assignee not sort issue. --- models/issues/issue_list.go | 9 ++++++++- models/organization/team_repo.go | 1 + models/repo/user_repo.go | 16 ++++++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/models/issues/issue_list.go b/models/issues/issue_list.go index 20e9949b66202..9e1e76cf399a5 100644 --- a/models/issues/issue_list.go +++ b/models/issues/issue_list.go @@ -12,6 +12,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/container" + "code.gitea.io/gitea/modules/setting" "xorm.io/builder" ) @@ -234,6 +235,12 @@ func (issues IssueList) loadAssignees(ctx context.Context) error { assignees := make(map[int64][]*user_model.User, len(issues)) issueIDs := issues.getIssueIDs() + + orderBy := "name" + if setting.UI.DefaultShowFullName { + orderBy = "full_name" + } + left := len(issueIDs) for left > 0 { limit := db.DefaultMaxInSize @@ -242,7 +249,7 @@ func (issues IssueList) loadAssignees(ctx context.Context) error { } rows, err := db.GetEngine(ctx).Table("issue_assignees"). Join("INNER", "`user`", "`user`.id = `issue_assignees`.assignee_id"). - In("`issue_assignees`.issue_id", issueIDs[:limit]). + In("`issue_assignees`.issue_id", issueIDs[:limit]).OrderBy(orderBy). Rows(new(AssigneeIssue)) if err != nil { return err diff --git a/models/organization/team_repo.go b/models/organization/team_repo.go index 717d754c40b7f..e7bea26c8bc73 100644 --- a/models/organization/team_repo.go +++ b/models/organization/team_repo.go @@ -81,5 +81,6 @@ func GetTeamsWithAccessToRepo(ctx context.Context, orgID, repoID int64, mode per Join("INNER", "team_repo", "team_repo.team_id = team.id"). And("team_repo.org_id = ?", orgID). And("team_repo.repo_id = ?", repoID). + OrderBy("name"). Find(&teams) } diff --git a/models/repo/user_repo.go b/models/repo/user_repo.go index e697505b81e4e..caebca070be0c 100644 --- a/models/repo/user_repo.go +++ b/models/repo/user_repo.go @@ -10,6 +10,7 @@ import ( "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/perm" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" "xorm.io/builder" @@ -109,7 +110,13 @@ func GetRepoAssignees(ctx context.Context, repo *Repository) (_ []*user_model.Us // and just waste 1 unit is cheaper than re-allocate memory once. users := make([]*user_model.User, 0, len(userIDs)+1) if len(userIDs) > 0 { - if err = e.In("id", userIDs).Find(&users); err != nil { + + orderBy := "name" + if setting.UI.DefaultShowFullName { + orderBy = "full_name" + } + + if err = e.In("id", userIDs).OrderBy(orderBy).Find(&users); err != nil { return nil, err } } @@ -167,6 +174,11 @@ func GetReviewers(ctx context.Context, repo *Repository, doerID, posterID int64) ))))) } + orderBy := "name" + if setting.UI.DefaultShowFullName { + orderBy = "full_name" + } + users := make([]*user_model.User, 0, 8) - return users, db.GetEngine(ctx).Where(cond).OrderBy("name").Find(&users) + return users, db.GetEngine(ctx).Where(cond).OrderBy(orderBy).Find(&users) } From 2da0afa05852b0cc4a7e9e74cbe380ff8c36a589 Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Sat, 9 Jul 2022 06:10:45 +0800 Subject: [PATCH 2/5] Create GetOrderBy function --- models/issues/issue_list.go | 8 +------- models/repo/user_repo.go | 16 ++-------------- models/user/user.go | 7 +++++++ 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/models/issues/issue_list.go b/models/issues/issue_list.go index 9e1e76cf399a5..eaf0310d54477 100644 --- a/models/issues/issue_list.go +++ b/models/issues/issue_list.go @@ -12,7 +12,6 @@ import ( repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/container" - "code.gitea.io/gitea/modules/setting" "xorm.io/builder" ) @@ -236,11 +235,6 @@ func (issues IssueList) loadAssignees(ctx context.Context) error { assignees := make(map[int64][]*user_model.User, len(issues)) issueIDs := issues.getIssueIDs() - orderBy := "name" - if setting.UI.DefaultShowFullName { - orderBy = "full_name" - } - left := len(issueIDs) for left > 0 { limit := db.DefaultMaxInSize @@ -249,7 +243,7 @@ func (issues IssueList) loadAssignees(ctx context.Context) error { } rows, err := db.GetEngine(ctx).Table("issue_assignees"). Join("INNER", "`user`", "`user`.id = `issue_assignees`.assignee_id"). - In("`issue_assignees`.issue_id", issueIDs[:limit]).OrderBy(orderBy). + In("`issue_assignees`.issue_id", issueIDs[:limit]).OrderBy(user_model.GetOrderBy()). Rows(new(AssigneeIssue)) if err != nil { return err diff --git a/models/repo/user_repo.go b/models/repo/user_repo.go index caebca070be0c..9cc425f83e2eb 100644 --- a/models/repo/user_repo.go +++ b/models/repo/user_repo.go @@ -10,7 +10,6 @@ import ( "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/perm" user_model "code.gitea.io/gitea/models/user" - "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" "xorm.io/builder" @@ -110,13 +109,7 @@ func GetRepoAssignees(ctx context.Context, repo *Repository) (_ []*user_model.Us // and just waste 1 unit is cheaper than re-allocate memory once. users := make([]*user_model.User, 0, len(userIDs)+1) if len(userIDs) > 0 { - - orderBy := "name" - if setting.UI.DefaultShowFullName { - orderBy = "full_name" - } - - if err = e.In("id", userIDs).OrderBy(orderBy).Find(&users); err != nil { + if err = e.In("id", userIDs).OrderBy(user_model.GetOrderBy()).Find(&users); err != nil { return nil, err } } @@ -174,11 +167,6 @@ func GetReviewers(ctx context.Context, repo *Repository, doerID, posterID int64) ))))) } - orderBy := "name" - if setting.UI.DefaultShowFullName { - orderBy = "full_name" - } - users := make([]*user_model.User, 0, 8) - return users, db.GetEngine(ctx).Where(cond).OrderBy(orderBy).Find(&users) + return users, db.GetEngine(ctx).Where(cond).OrderBy(user_model.GetOrderBy()).Find(&users) } diff --git a/models/user/user.go b/models/user/user.go index f7d457b91b5a5..b74ae39c119a3 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -1270,3 +1270,10 @@ func IsUserVisibleToViewer(ctx context.Context, u, viewer *User) bool { } return false } + +func GetOrderBy() string { + if setting.UI.DefaultShowFullName { + return "full_name" + } + return "name" +} From f1af2919ddfb31b3f87bb61ee28fc6abce3c49e0 Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Sat, 9 Jul 2022 06:11:58 +0800 Subject: [PATCH 3/5] Remove break line --- models/issues/issue_list.go | 1 - 1 file changed, 1 deletion(-) diff --git a/models/issues/issue_list.go b/models/issues/issue_list.go index eaf0310d54477..6f124f5b4931f 100644 --- a/models/issues/issue_list.go +++ b/models/issues/issue_list.go @@ -234,7 +234,6 @@ func (issues IssueList) loadAssignees(ctx context.Context) error { assignees := make(map[int64][]*user_model.User, len(issues)) issueIDs := issues.getIssueIDs() - left := len(issueIDs) for left > 0 { limit := db.DefaultMaxInSize From 088a78c764eabd8efffc358053171730d276ffc0 Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Thu, 14 Jul 2022 18:28:35 +0800 Subject: [PATCH 4/5] Update models/user/user.go Co-authored-by: wxiaoguang --- models/user/user.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/user/user.go b/models/user/user.go index b74ae39c119a3..30026064a2c97 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -1273,7 +1273,7 @@ func IsUserVisibleToViewer(ctx context.Context, u, viewer *User) bool { func GetOrderBy() string { if setting.UI.DefaultShowFullName { - return "full_name" + return "full_name, name" } return "name" } From dfd13f6e8b393bd99ec8d8c9421ecbd0d29c1045 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 14 Jul 2022 20:18:17 +0800 Subject: [PATCH 5/5] GetOrderBy is too general, use GetOrderByName instead --- models/issues/issue_list.go | 2 +- models/repo/user_repo.go | 4 ++-- models/user/user.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/models/issues/issue_list.go b/models/issues/issue_list.go index 6f124f5b4931f..e311e80b1d668 100644 --- a/models/issues/issue_list.go +++ b/models/issues/issue_list.go @@ -242,7 +242,7 @@ func (issues IssueList) loadAssignees(ctx context.Context) error { } rows, err := db.GetEngine(ctx).Table("issue_assignees"). Join("INNER", "`user`", "`user`.id = `issue_assignees`.assignee_id"). - In("`issue_assignees`.issue_id", issueIDs[:limit]).OrderBy(user_model.GetOrderBy()). + In("`issue_assignees`.issue_id", issueIDs[:limit]).OrderBy(user_model.GetOrderByName()). Rows(new(AssigneeIssue)) if err != nil { return err diff --git a/models/repo/user_repo.go b/models/repo/user_repo.go index 9cc425f83e2eb..71e0c57550c56 100644 --- a/models/repo/user_repo.go +++ b/models/repo/user_repo.go @@ -109,7 +109,7 @@ func GetRepoAssignees(ctx context.Context, repo *Repository) (_ []*user_model.Us // and just waste 1 unit is cheaper than re-allocate memory once. users := make([]*user_model.User, 0, len(userIDs)+1) if len(userIDs) > 0 { - if err = e.In("id", userIDs).OrderBy(user_model.GetOrderBy()).Find(&users); err != nil { + if err = e.In("id", userIDs).OrderBy(user_model.GetOrderByName()).Find(&users); err != nil { return nil, err } } @@ -168,5 +168,5 @@ func GetReviewers(ctx context.Context, repo *Repository, doerID, posterID int64) } users := make([]*user_model.User, 0, 8) - return users, db.GetEngine(ctx).Where(cond).OrderBy(user_model.GetOrderBy()).Find(&users) + return users, db.GetEngine(ctx).Where(cond).OrderBy(user_model.GetOrderByName()).Find(&users) } diff --git a/models/user/user.go b/models/user/user.go index 30f23aa3ecc73..fbd8df9472472 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -1315,7 +1315,7 @@ func IsUserVisibleToViewer(ctx context.Context, u, viewer *User) bool { return false } -func GetOrderBy() string { +func GetOrderByName() string { if setting.UI.DefaultShowFullName { return "full_name, name" }