diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-04-15 03:29:05 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-14 15:29:05 -0400 |
commit | 2902d1e9d193a157bccd46cdda449de5443a2fd8 (patch) | |
tree | c443573b022bbe1266cc08900585eb8d97fa93bf /models/repo/topic.go | |
parent | ed81b608cb5bd94ef518393cdd724c4fac1215d4 (diff) | |
download | gitea-2902d1e9d193a157bccd46cdda449de5443a2fd8.tar.gz gitea-2902d1e9d193a157bccd46cdda449de5443a2fd8.zip |
Sort repo topic labels by name (#24123)
Close #24077
Diffstat (limited to 'models/repo/topic.go')
-rw-r--r-- | models/repo/topic.go | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/models/repo/topic.go b/models/repo/topic.go index 05f50cfe46..88fe532be9 100644 --- a/models/repo/topic.go +++ b/models/repo/topic.go @@ -194,14 +194,16 @@ func (opts *FindTopicOptions) toConds() builder.Cond { // FindTopics retrieves the topics via FindTopicOptions func FindTopics(opts *FindTopicOptions) ([]*Topic, int64, error) { sess := db.GetEngine(db.DefaultContext).Select("topic.*").Where(opts.toConds()) + orderBy := "topic.repo_count DESC" if opts.RepoID > 0 { sess.Join("INNER", "repo_topic", "repo_topic.topic_id = topic.id") + orderBy = "topic.name" // when render topics for a repo, it's better to sort them by name, to get consistent result } if opts.PageSize != 0 && opts.Page != 0 { sess = db.SetSessionPagination(sess, opts) } topics := make([]*Topic, 0, 10) - total, err := sess.Desc("topic.repo_count").FindAndCount(&topics) + total, err := sess.OrderBy(orderBy).FindAndCount(&topics) return topics, total, err } |