From cf313933c936e4ca3c4a788bf56d3ccdb177dd04 Mon Sep 17 00:00:00 2001 From: stg-annon <14135675+stg-annon@users.noreply.github.com> Date: Wed, 4 Dec 2024 11:21:15 -0500 Subject: [PATCH] more backend changes override "name" sort with COALESCE --- pkg/sqlite/database.go | 2 +- pkg/sqlite/tag.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/sqlite/database.go b/pkg/sqlite/database.go index 5ed803c1753..4b7c23552d1 100644 --- a/pkg/sqlite/database.go +++ b/pkg/sqlite/database.go @@ -34,7 +34,7 @@ const ( cacheSizeEnv = "STASH_SQLITE_CACHE_SIZE" ) -var appSchemaVersion uint = 71 +var appSchemaVersion uint = 72 //go:embed migrations/*.sql var migrationsBox embed.FS diff --git a/pkg/sqlite/tag.go b/pkg/sqlite/tag.go index ebfe1086096..6a31df2ef08 100644 --- a/pkg/sqlite/tag.go +++ b/pkg/sqlite/tag.go @@ -33,6 +33,7 @@ const ( type tagRow struct { ID int `db:"id" goqu:"skipinsert"` Name null.String `db:"name"` // TODO: make schema non-nullable + SortName zero.String `db:"sort_name"` Favorite bool `db:"favorite"` Description zero.String `db:"description"` IgnoreAutoTag bool `db:"ignore_auto_tag"` @@ -46,6 +47,7 @@ type tagRow struct { func (r *tagRow) fromTag(o models.Tag) { r.ID = o.ID r.Name = null.StringFrom(o.Name) + r.SortName = zero.StringFrom((o.SortName)) r.Favorite = o.Favorite r.Description = zero.StringFrom(o.Description) r.IgnoreAutoTag = o.IgnoreAutoTag @@ -57,6 +59,7 @@ func (r *tagRow) resolve() *models.Tag { ret := &models.Tag{ ID: r.ID, Name: r.Name.String, + SortName: r.SortName.String, Favorite: r.Favorite, Description: r.Description.String, IgnoreAutoTag: r.IgnoreAutoTag, @@ -87,6 +90,7 @@ type tagRowRecord struct { func (r *tagRowRecord) fromPartial(o models.TagPartial) { r.setString("name", o.Name) + r.setNullString("sort_name", o.SortName) r.setNullString("description", o.Description) r.setBool("favorite", o.Favorite) r.setBool("ignore_auto_tag", o.IgnoreAutoTag) @@ -672,6 +676,8 @@ func (qb *TagStore) getTagSort(query *queryBuilder, findFilter *models.FindFilte sortQuery := "" switch sort { + case "name": + sortQuery += fmt.Sprintf(" ORDER BY COALESCE(tags.sort_name, tags.name, tags.id) COLLATE NATURAL_CI %s", getSortDirection(direction)) case "scenes_count": sortQuery += getCountSort(tagTable, scenesTagsTable, tagIDColumn, direction) case "scene_markers_count":