Sort repo topic labels by name (#24123)

Close #24077
This commit is contained in:
wxiaoguang 2023-04-15 03:29:05 +08:00 committed by GitHub
parent ed81b608cb
commit 2902d1e9d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 9 deletions

View file

@ -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
}