Skip to content

Commit

Permalink
init backend for sort_name for tags
Browse files Browse the repository at this point in the history
this could go nowhere, testing things out
  • Loading branch information
stg-annon committed Dec 4, 2024
1 parent 0621d87 commit 788d040
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions graphql/schema/types/filters.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,9 @@ input TagFilterType {
"Filter by tag name"
name: StringCriterionInput

"Filter by tag sort_name"
sort_name: StringCriterionInput

"Filter by tag aliases"
aliases: StringCriterionInput

Expand Down
6 changes: 6 additions & 0 deletions graphql/schema/types/tag.graphql
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
type Tag {
id: ID!
name: String!
"Value that does not appear in the UI but overrides name for sorting"
sort_name: String
description: String
aliases: [String!]!
ignore_auto_tag: Boolean!
Expand All @@ -25,6 +27,8 @@ type Tag {

input TagCreateInput {
name: String!
"Value that does not appear in the UI but overrides name for sorting"
sort_name: String
description: String
aliases: [String!]
ignore_auto_tag: Boolean
Expand All @@ -39,6 +43,8 @@ input TagCreateInput {
input TagUpdateInput {
id: ID!
name: String
"Value that does not appear in the UI but overrides name for sorting"
sort_name: String
description: String
aliases: [String!]
ignore_auto_tag: Boolean
Expand Down
2 changes: 2 additions & 0 deletions internal/api/resolver_mutation_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func (r *mutationResolver) TagCreate(ctx context.Context, input TagCreateInput)
newTag := models.NewTag()

newTag.Name = input.Name
newTag.SortName = translator.string(input.SortName)
newTag.Aliases = models.NewRelatedStrings(input.Aliases)
newTag.Favorite = translator.bool(input.Favorite)
newTag.Description = translator.string(input.Description)
Expand Down Expand Up @@ -102,6 +103,7 @@ func (r *mutationResolver) TagUpdate(ctx context.Context, input TagUpdateInput)
updatedTag := models.NewTagPartial()

updatedTag.Name = translator.optionalString(input.Name, "name")
updatedTag.SortName = translator.optionalString(input.SortName, "sort_name")
updatedTag.Favorite = translator.optionalBool(input.Favorite, "favorite")
updatedTag.IgnoreAutoTag = translator.optionalBool(input.IgnoreAutoTag, "ignore_auto_tag")
updatedTag.Description = translator.optionalString(input.Description, "description")
Expand Down
2 changes: 2 additions & 0 deletions pkg/models/model_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
type Tag struct {
ID int `json:"id"`
Name string `json:"name"`
SortName string `json:"sort_name"`
Favorite bool `json:"favorite"`
Description string `json:"description"`
IgnoreAutoTag bool `json:"ignore_auto_tag"`
Expand Down Expand Up @@ -47,6 +48,7 @@ func (s *Tag) LoadChildIDs(ctx context.Context, l TagRelationLoader) error {

type TagPartial struct {
Name OptionalString
SortName OptionalString
Description OptionalString
Favorite OptionalBool
IgnoreAutoTag OptionalBool
Expand Down
2 changes: 2 additions & 0 deletions pkg/models/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ type TagFilterType struct {
OperatorFilter[TagFilterType]
// Filter by tag name
Name *StringCriterionInput `json:"name"`
// Filter by tag sort_name
SortName *StringCriterionInput `json:"sort_name"`
// Filter by tag aliases
Aliases *StringCriterionInput `json:"aliases"`
// Filter by tag favorites
Expand Down
2 changes: 2 additions & 0 deletions pkg/sqlite/migrations/72_tag_sort_name.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE `performer_stash_ids` ADD COLUMN `sort_name` varchar(255);

4 changes: 2 additions & 2 deletions pkg/sqlite/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,8 +690,8 @@ func (qb *TagStore) getTagSort(query *queryBuilder, findFilter *models.FindFilte
sortQuery += getSort(sort, direction, "tags")
}

// Whatever the sorting, always use name/id as a final sort
sortQuery += ", COALESCE(tags.name, tags.id) COLLATE NATURAL_CI ASC"
// Whatever the sorting, always use sort_name/name/id as a final sort
sortQuery += ", COALESCE(tags.sort_name, tags.name, tags.id) COLLATE NATURAL_CI ASC"
return sortQuery, nil
}

Expand Down

0 comments on commit 788d040

Please sign in to comment.