diff options
author | techknowlogick <techknowlogick@gitea.io> | 2023-05-06 10:04:55 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-06 22:04:55 +0800 |
commit | 4daf40505a5f89747982ddd2f1df2a4001720846 (patch) | |
tree | 7d4fa0818138bf80c4e28d81bd7ef3fb70b7f0ee /routers/web/explore/user.go | |
parent | 46679554d01b0475b4339fb3c5fec96da3a7e202 (diff) | |
download | gitea-4daf40505a5f89747982ddd2f1df2a4001720846.tar.gz gitea-4daf40505a5f89747982ddd2f1df2a4001720846.zip |
Sort users and orgs on explore by recency by default (#24279)
This gives more "freshness" to the explore page. So it's not just the
same X users on the explore page by default, now it matches the same
sort as the repos on the explore page.
---------
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'routers/web/explore/user.go')
-rw-r--r-- | routers/web/explore/user.go | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/routers/web/explore/user.go b/routers/web/explore/user.go index e00493c87b..a2b5f80099 100644 --- a/routers/web/explore/user.go +++ b/routers/web/explore/user.go @@ -24,7 +24,10 @@ const ( ) // UserSearchDefaultSortType is the default sort type for user search -const UserSearchDefaultSortType = "alphabetically" +const ( + UserSearchDefaultSortType = "recentupdate" + UserSearchDefaultAdminSort = "alphabetically" +) var nullByte = []byte{0x00} @@ -56,14 +59,13 @@ func RenderUserSearch(ctx *context.Context, opts *user_model.SearchUserOptions, ) // we can not set orderBy to `models.SearchOrderByXxx`, because there may be a JOIN in the statement, different tables may have the same name columns + ctx.Data["SortType"] = ctx.FormString("sort") switch ctx.FormString("sort") { case "newest": orderBy = "`user`.id DESC" case "oldest": orderBy = "`user`.id ASC" - case "recentupdate": - orderBy = "`user`.updated_unix DESC" case "leastupdate": orderBy = "`user`.updated_unix ASC" case "reversealphabetically": @@ -72,10 +74,14 @@ func RenderUserSearch(ctx *context.Context, opts *user_model.SearchUserOptions, orderBy = "`user`.last_login_unix ASC" case "reverselastlogin": orderBy = "`user`.last_login_unix DESC" - case UserSearchDefaultSortType: // "alphabetically" - default: + case "alphabetically": orderBy = "`user`.name ASC" - ctx.Data["SortType"] = UserSearchDefaultSortType + case "recentupdate": + fallthrough + default: + // in case the sortType is not valid, we set it to recentupdate + ctx.Data["SortType"] = "recentupdate" + orderBy = "`user`.updated_unix DESC" } opts.Keyword = ctx.FormTrim("q") @@ -127,6 +133,10 @@ func Users(ctx *context.Context) { ctx.Data["PageIsExploreUsers"] = true ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled + if ctx.FormString("sort") == "" { + ctx.SetFormString("sort", UserSearchDefaultSortType) + } + RenderUserSearch(ctx, &user_model.SearchUserOptions{ Actor: ctx.Doer, Type: user_model.UserTypeIndividual, |