Displayed order of topics is inconsistent between repo list and repo page #12387

Closed
opened 2025-11-02 10:08:12 -06:00 by GiteaMirror · 4 comments
Owner

Originally created by @wackbyte on GitHub (Jan 26, 2024).

Description

Problem

The order of a repository's topics is different when viewed in a repo list versus when viewed on the repo's page itself. See the screenshots below for an example.

Expected behavior

I would expect the ordering to be consistent between the two pages, either by being sorted or by staying in insertion order. Personally, I would prefer them to be sorted (as they already are on the repo page).

Demo

Screenshots

Order while adding:
Entering the topics A, C, and B in that order

Order after adding (on repo page):
List of topics A, B, and C in that order

Order in the repo list on the user profile:
List of topics A, C, and B in that order

(These screenshots are from the reproduction of the issue on a local test instance I built, not from try.gitea.io, but the same issue occurs there.)

Gitea Version

ba24e0ba61

Can you reproduce the bug on the Gitea demo site?

Yes

Operating System

NixOS

Browser Version

Librewolf 121.0.1

Originally created by @wackbyte on GitHub (Jan 26, 2024). ### Description #### Problem The order of a repository's topics is different when viewed in a repo list versus when viewed on the repo's page itself. See the screenshots below for an example. #### Expected behavior I would expect the ordering to be consistent between the two pages, either by being sorted or by staying in insertion order. Personally, I would prefer them to be sorted (as they already are on the repo page). #### Demo - Repo list <https://try.gitea.io/glaggleland> - Repo page: <https://try.gitea.io/glaggleland/topics> ### Screenshots Order while adding: ![Entering the topics A, C, and B in that order](https://github.com/go-gitea/gitea/assets/29505620/ecd76c29-6b38-45de-a0cd-ec13073f3b6a) Order after adding (on repo page): ![List of topics A, B, and C in that order](https://github.com/go-gitea/gitea/assets/29505620/401052f6-9ff4-4891-b3cc-d4b433002083) Order in the repo list on the user profile: ![List of topics A, C, and B in that order](https://github.com/go-gitea/gitea/assets/29505620/4cb33862-a260-47e9-92b1-8539f617bd8d) (These screenshots are from the reproduction of the issue on a local test instance I built, not from try.gitea.io, but the same issue occurs there.) ### Gitea Version ba24e0ba61b1b66f58c8448f27272d1d6d14f60c ### Can you reproduce the bug on the Gitea demo site? Yes ### Operating System NixOS ### Browser Version Librewolf 121.0.1
GiteaMirror added the topic/uitype/bug labels 2025-11-02 10:08:12 -06:00
Author
Owner

@wackbyte commented on GitHub (Jan 26, 2024):

I believe I've found the root of the issue.

The repo page (view, template) uses FindTopics to get the list of topics, which sorts them by name.

However, the repo list (view, template) uses the Topics field of the Repository struct, which I assume is not sorted.

EDIT: The code that generates the Topics field (syncTopicsInRepository) sorts by the repo count of each topic, not by name. I replaced .Desc("topic.repo_count") with .Asc("topic.name"), and the issue was fixed once I triggered a sync by editing the repo's topics.

@wackbyte commented on GitHub (Jan 26, 2024): I believe I've found the root of the issue. The repo page ([view](https://github.com/go-gitea/gitea/blob/ba24e0ba61b1b66f58c8448f27272d1d6d14f60c/routers/web/repo/view.go#L938), [template](https://github.com/go-gitea/gitea/blob/ba24e0ba61b1b66f58c8448f27272d1d6d14f60c/templates/repo/home.tmpl#L33)) uses [`FindTopics`](https://github.com/go-gitea/gitea/blob/ba24e0ba61b1b66f58c8448f27272d1d6d14f60c/models/repo/topic.go#L200) to get the list of topics, which sorts them by name. However, the repo list ([view](https://github.com/go-gitea/gitea/blob/ba24e0ba61b1b66f58c8448f27272d1d6d14f60c/routers/web/explore/repo.go#L147), [template](https://github.com/go-gitea/gitea/blob/ba24e0ba61b1b66f58c8448f27272d1d6d14f60c/templates/explore/repo_list.tmpl#L51)) uses the [`Topics` field of the `Repository` struct](https://github.com/go-gitea/gitea/blob/ba24e0ba61b1b66f58c8448f27272d1d6d14f60c/models/repo/repo.go#L182), which I assume is not sorted. EDIT: The code that generates the `Topics` field ([`syncTopicsInRepository`](https://github.com/go-gitea/gitea/blob/ba24e0ba61b1b66f58c8448f27272d1d6d14f60c/models/repo/topic.go#L369)) sorts by the repo count of each topic, not by name. I replaced `.Desc("topic.repo_count")` with `.Asc("topic.name")`, and the issue was fixed once I triggered a sync by editing the repo's topics.
Author
Owner

@stuzer05 commented on GitHub (Jan 26, 2024):

Can we fix milestones list sorting as well? It's not alphabetical

@stuzer05 commented on GitHub (Jan 26, 2024): Can we fix milestones list sorting as well? It's not alphabetical
Author
Owner

@wackbyte commented on GitHub (Jan 26, 2024):

I can look into it

@wackbyte commented on GitHub (Jan 26, 2024): I can look into it
Author
Owner

@github-actions[bot] commented on GitHub (Feb 29, 2024):

Automatically locked because of our CONTRIBUTING guidelines

@github-actions[bot] commented on GitHub (Feb 29, 2024): Automatically locked because of our [CONTRIBUTING guidelines](https://github.com/go-gitea/gitea/blob/main/CONTRIBUTING.md#issue-locking)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#12387