Correct title ordering for objects without titles (#3244)

* Correct scene title ordering
* Correct ordering for other objects
* Add basename function, add to gallery title sort
This commit is contained in:
WithoutPants 2022-12-09 08:29:34 +11:00 committed by GitHub
parent 78bb2d8425
commit eb7956a05a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 17 additions and 3 deletions

View File

@ -428,6 +428,7 @@ func registerCustomDriver() {
funcs := map[string]interface{}{
"regexp": regexFn,
"durationToTinyInt": durationToTinyIntFn,
"basename": basenameFn,
}
for name, fn := range funcs {

View File

@ -1,6 +1,7 @@
package sqlite
import (
"path/filepath"
"strconv"
"strings"
)
@ -30,3 +31,7 @@ func durationToTinyIntFn(str string) (int64, error) {
return int64(seconds), nil
}
func basenameFn(str string) (string, error) {
return filepath.Base(str), nil
}

View File

@ -1109,7 +1109,7 @@ func (qb *GalleryStore) setGallerySort(query *queryBuilder, findFilter *models.F
case "title":
addFileTable()
addFolderTable()
query.sortAndPagination += " ORDER BY galleries.title COLLATE NATURAL_CS " + direction + ", folders.path " + direction + ", file_folder.path " + direction + ", files.basename COLLATE NATURAL_CS " + direction
query.sortAndPagination += " ORDER BY COALESCE(galleries.title, files.basename, basename(COALESCE(folders.path, ''))) COLLATE NATURAL_CS " + direction + ", file_folder.path " + direction
default:
query.sortAndPagination += getSort(sort, direction, "galleries")
}

View File

@ -2414,6 +2414,13 @@ func TestGalleryQuerySorting(t *testing.T) {
-1,
-1,
},
{
"title",
"title",
models.SortDirectionEnumDesc,
-1,
-1,
},
}
qb := db.Gallery

View File

@ -1019,7 +1019,7 @@ func (qb *ImageStore) setImageSortAndPagination(q *queryBuilder, findFilter *mod
case "title":
addFilesJoin()
addFolderJoin()
sortClause = " ORDER BY images.title COLLATE NATURAL_CS " + direction + ", folders.path " + direction + ", files.basename COLLATE NATURAL_CS " + direction
sortClause = " ORDER BY COALESCE(images.title, files.basename) COLLATE NATURAL_CS " + direction + ", folders.path " + direction
default:
sortClause = getSort(sort, direction, "images")
}

View File

@ -1446,7 +1446,7 @@ func (qb *SceneStore) setSceneSort(query *queryBuilder, findFilter *models.FindF
case "title":
addFileTable()
addFolderTable()
query.sortAndPagination += " ORDER BY scenes.title COLLATE NATURAL_CS " + direction + ", folders.path " + direction + ", files.basename COLLATE NATURAL_CS " + direction
query.sortAndPagination += " ORDER BY COALESCE(scenes.title, files.basename) COLLATE NATURAL_CS " + direction + ", folders.path " + direction
case "play_count":
// handle here since getSort has special handling for _count suffix
query.sortAndPagination += " ORDER BY scenes.play_count " + direction

View File

@ -9,6 +9,7 @@
* Changed performer aliases to be a list, rather than a string field. ([#3113](https://github.com/stashapp/stash/pull/3113))
### 🐛 Bug fixes
* Fixed objects without titles not being sorted correctly with objects with titles. ([#3244](https://github.com/stashapp/stash/pull/3244))
* Fixed incorrect new Performer pill being removed when creating Performer from scrape dialog. ([#3251](https://github.com/stashapp/stash/pull/3251))
* Fixed date fields not being nulled correctly when cleared. ([#3243](https://github.com/stashapp/stash/pull/3243))
* Fixed scene wall items to show file base name where scene has no title set. ([#3242](https://github.com/stashapp/stash/pull/3242))