feat(subsonic): Sorting like file explorers - #710
Open
ummshsh wants to merge 2 commits into
Open
Conversation
Author
|
This approach targets only folders, I don't know if it makes sense to do the same for individual tracks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Good day!
I thought it makes sense to have option to see folders sorted just like you see them in file explorers. Certainly makes my live easier =)
Problem
Gonic sorts folder listings by
right_path COLLATE NOCASE— raw bytewise comparison. This means(sorts before_(ASCII 40 vs 95).File explorers (Finder, Explorer, Nautilus) use the Unicode Collation Algorithm, which gives
_a lower weight than(— so_1comes before(1992) One.Solution
Pre-computed sort key column — same approach file explorers use under the hood.
linguistic (UCA-based) folder sorting with admin toggle
What changed (10 files)
db/db.go— AddedRightPathSortKeyfield toAlbummodel + newLinguisticSortingsetting keydb/migrations.go— Migration202607051200adds the column viaAutoMigrateand backfills sort keys for all existing albums usinggolang.org/x/text/collatescanner/scanner.go—populateAlbumBasicsalways writes a UCA sort key from the directory basename during scanserver/ctrlsubsonic/ctrl.go— Three helper methods (sortRightPath,sortRightPathPrefixed,sortRightPathParentPrefixed) that check thelinguistic_sortingsetting and return eitherright_path_sort_keyorright_path COLLATE NOCASEserver/ctrlsubsonic/handlers_by_folder.go— All 6ORDER BYclauses switched to use helpersserver/ctrlsubsonic/handlers_by_tags.go— Tag-mode artist album listing switched to use helperserver/ctrladmin/handlers.go— Loads setting inServeHome, added POST handler to save toggleserver/ctrladmin/ctrl.go— Registered route, addedLinguisticSortingto template dataserver/ctrladmin/adminui/pages/home.tmpl— New "sorting" block with dropdown (bytewise / linguistic)go.mod— Promotedgolang.org/x/textto direct dependencyHow it works
The sort key is always written during scanning regardless of the toggle. The toggle (
/admin/home→ sorting dropdown) only changes which column theORDER BYuses at query time — zero-rebuild, instant switch. Migration backfills existing albums so there's no gap.Migration behavior
On upgrade,
migrateAlbumRightPathSortKey:right_path_sort_key TEXTcolumn viaAutoMigrateright_pathusing UCA