Revert "sort all urls alphabetically"

This reverts commit c4c5d2d64d.
This commit is contained in:
Gykes 2025-12-01 19:27:30 -08:00
parent f2b4a4266d
commit 38208c5a1d
7 changed files with 13 additions and 117 deletions

View file

@ -12,7 +12,6 @@ import (
"github.com/doug-martin/goqu/v9/exp"
"github.com/jmoiron/sqlx"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/utils"
"gopkg.in/guregu/null.v4"
"gopkg.in/guregu/null.v4/zero"
)
@ -247,10 +246,8 @@ func (qb *GalleryStore) Create(ctx context.Context, newObject *models.Gallery, f
}
if newObject.URLs.Loaded() {
urls := newObject.URLs.List()
utils.SortURLs(urls)
const startPos = 0
if err := galleriesURLsTableMgr.insertJoins(ctx, id, startPos, urls); err != nil {
if err := galleriesURLsTableMgr.insertJoins(ctx, id, startPos, newObject.URLs.List()); err != nil {
return err
}
}
@ -289,9 +286,7 @@ func (qb *GalleryStore) Update(ctx context.Context, updatedObject *models.Galler
}
if updatedObject.URLs.Loaded() {
urls := updatedObject.URLs.List()
utils.SortURLs(urls)
if err := galleriesURLsTableMgr.replaceJoins(ctx, updatedObject.ID, urls); err != nil {
if err := galleriesURLsTableMgr.replaceJoins(ctx, updatedObject.ID, updatedObject.URLs.List()); err != nil {
return err
}
}
@ -344,15 +339,6 @@ func (qb *GalleryStore) UpdatePartial(ctx context.Context, id int, partial model
if err := galleriesURLsTableMgr.modifyJoins(ctx, id, partial.URLs.Values, partial.URLs.Mode); err != nil {
return nil, err
}
// Re-sort URLs after modification
urls, err := galleriesURLsTableMgr.get(ctx, id)
if err != nil {
return nil, err
}
utils.SortURLs(urls)
if err := galleriesURLsTableMgr.replaceJoins(ctx, id, urls); err != nil {
return nil, err
}
}
if partial.PerformerIDs != nil {
if err := galleriesPerformersTableMgr.modifyJoins(ctx, id, partial.PerformerIDs.IDs, partial.PerformerIDs.Mode); err != nil {

View file

@ -14,7 +14,6 @@ import (
"gopkg.in/guregu/null.v4/zero"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/utils"
)
const (
@ -173,10 +172,8 @@ func (qb *GroupStore) Create(ctx context.Context, newObject *models.Group) error
}
if newObject.URLs.Loaded() {
urls := newObject.URLs.List()
utils.SortURLs(urls)
const startPos = 0
if err := groupsURLsTableMgr.insertJoins(ctx, id, startPos, urls); err != nil {
if err := groupsURLsTableMgr.insertJoins(ctx, id, startPos, newObject.URLs.List()); err != nil {
return err
}
}
@ -222,15 +219,6 @@ func (qb *GroupStore) UpdatePartial(ctx context.Context, id int, partial models.
if err := groupsURLsTableMgr.modifyJoins(ctx, id, partial.URLs.Values, partial.URLs.Mode); err != nil {
return nil, err
}
// Re-sort URLs after modification
urls, err := groupsURLsTableMgr.get(ctx, id)
if err != nil {
return nil, err
}
utils.SortURLs(urls)
if err := groupsURLsTableMgr.replaceJoins(ctx, id, urls); err != nil {
return nil, err
}
}
if err := qb.tagRelationshipStore.modifyRelationships(ctx, id, partial.TagIDs); err != nil {
@ -257,9 +245,7 @@ func (qb *GroupStore) Update(ctx context.Context, updatedObject *models.Group) e
}
if updatedObject.URLs.Loaded() {
urls := updatedObject.URLs.List()
utils.SortURLs(urls)
if err := groupsURLsTableMgr.replaceJoins(ctx, updatedObject.ID, urls); err != nil {
if err := groupsURLsTableMgr.replaceJoins(ctx, updatedObject.ID, updatedObject.URLs.List()); err != nil {
return err
}
}

View file

@ -11,7 +11,6 @@ import (
"github.com/jmoiron/sqlx"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/sliceutil"
"github.com/stashapp/stash/pkg/utils"
"gopkg.in/guregu/null.v4"
"gopkg.in/guregu/null.v4/zero"
@ -252,10 +251,8 @@ func (qb *ImageStore) Create(ctx context.Context, newObject *models.Image, fileI
}
if newObject.URLs.Loaded() {
urls := newObject.URLs.List()
utils.SortURLs(urls)
const startPos = 0
if err := imagesURLsTableMgr.insertJoins(ctx, id, startPos, urls); err != nil {
if err := imagesURLsTableMgr.insertJoins(ctx, id, startPos, newObject.URLs.List()); err != nil {
return err
}
}
@ -312,15 +309,6 @@ func (qb *ImageStore) UpdatePartial(ctx context.Context, id int, partial models.
if err := imagesURLsTableMgr.modifyJoins(ctx, id, partial.URLs.Values, partial.URLs.Mode); err != nil {
return nil, err
}
// Re-sort URLs after modification
urls, err := imagesURLsTableMgr.get(ctx, id)
if err != nil {
return nil, err
}
utils.SortURLs(urls)
if err := imagesURLsTableMgr.replaceJoins(ctx, id, urls); err != nil {
return nil, err
}
}
if partial.PerformerIDs != nil {
if err := imagesPerformersTableMgr.modifyJoins(ctx, id, partial.PerformerIDs.IDs, partial.PerformerIDs.Mode); err != nil {
@ -351,9 +339,7 @@ func (qb *ImageStore) Update(ctx context.Context, updatedObject *models.Image) e
}
if updatedObject.URLs.Loaded() {
urls := updatedObject.URLs.List()
utils.SortURLs(urls)
if err := imagesURLsTableMgr.replaceJoins(ctx, updatedObject.ID, urls); err != nil {
if err := imagesURLsTableMgr.replaceJoins(ctx, updatedObject.ID, updatedObject.URLs.List()); err != nil {
return err
}
}

View file

@ -269,10 +269,8 @@ func (qb *PerformerStore) Create(ctx context.Context, newObject *models.CreatePe
}
if newObject.URLs.Loaded() {
urls := newObject.URLs.List()
utils.SortURLs(urls)
const startPos = 0
if err := performersURLsTableMgr.insertJoins(ctx, id, startPos, urls); err != nil {
if err := performersURLsTableMgr.insertJoins(ctx, id, startPos, newObject.URLs.List()); err != nil {
return err
}
}
@ -329,15 +327,6 @@ func (qb *PerformerStore) UpdatePartial(ctx context.Context, id int, partial mod
if err := performersURLsTableMgr.modifyJoins(ctx, id, partial.URLs.Values, partial.URLs.Mode); err != nil {
return nil, err
}
// Re-sort URLs after modification
urls, err := performersURLsTableMgr.get(ctx, id)
if err != nil {
return nil, err
}
utils.SortURLs(urls)
if err := performersURLsTableMgr.replaceJoins(ctx, id, urls); err != nil {
return nil, err
}
}
if partial.TagIDs != nil {
@ -373,9 +362,7 @@ func (qb *PerformerStore) Update(ctx context.Context, updatedObject *models.Upda
}
if updatedObject.URLs.Loaded() {
urls := updatedObject.URLs.List()
utils.SortURLs(urls)
if err := performersURLsTableMgr.replaceJoins(ctx, updatedObject.ID, urls); err != nil {
if err := performersURLsTableMgr.replaceJoins(ctx, updatedObject.ID, updatedObject.URLs.List()); err != nil {
return err
}
}

View file

@ -315,10 +315,8 @@ func (qb *SceneStore) Create(ctx context.Context, newObject *models.Scene, fileI
}
if newObject.URLs.Loaded() {
urls := newObject.URLs.List()
utils.SortURLs(urls)
const startPos = 0
if err := scenesURLsTableMgr.insertJoins(ctx, id, startPos, urls); err != nil {
if err := scenesURLsTableMgr.insertJoins(ctx, id, startPos, newObject.URLs.List()); err != nil {
return err
}
}
@ -381,15 +379,6 @@ func (qb *SceneStore) UpdatePartial(ctx context.Context, id int, partial models.
if err := scenesURLsTableMgr.modifyJoins(ctx, id, partial.URLs.Values, partial.URLs.Mode); err != nil {
return nil, err
}
// Re-sort URLs after modification
urls, err := scenesURLsTableMgr.get(ctx, id)
if err != nil {
return nil, err
}
utils.SortURLs(urls)
if err := scenesURLsTableMgr.replaceJoins(ctx, id, urls); err != nil {
return nil, err
}
}
if partial.PerformerIDs != nil {
if err := scenesPerformersTableMgr.modifyJoins(ctx, id, partial.PerformerIDs.IDs, partial.PerformerIDs.Mode); err != nil {
@ -434,9 +423,7 @@ func (qb *SceneStore) Update(ctx context.Context, updatedObject *models.Scene) e
}
if updatedObject.URLs.Loaded() {
urls := updatedObject.URLs.List()
utils.SortURLs(urls)
if err := scenesURLsTableMgr.replaceJoins(ctx, updatedObject.ID, urls); err != nil {
if err := scenesURLsTableMgr.replaceJoins(ctx, updatedObject.ID, updatedObject.URLs.List()); err != nil {
return err
}
}

View file

@ -15,7 +15,6 @@ import (
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/studio"
"github.com/stashapp/stash/pkg/utils"
)
const (
@ -192,10 +191,8 @@ func (qb *StudioStore) Create(ctx context.Context, newObject *models.Studio) err
}
if newObject.URLs.Loaded() {
urls := newObject.URLs.List()
utils.SortURLs(urls)
const startPos = 0
if err := studiosURLsTableMgr.insertJoins(ctx, id, startPos, urls); err != nil {
if err := studiosURLsTableMgr.insertJoins(ctx, id, startPos, newObject.URLs.List()); err != nil {
return err
}
}
@ -244,15 +241,6 @@ func (qb *StudioStore) UpdatePartial(ctx context.Context, input models.StudioPar
if err := studiosURLsTableMgr.modifyJoins(ctx, input.ID, input.URLs.Values, input.URLs.Mode); err != nil {
return nil, err
}
// Re-sort URLs after modification
urls, err := studiosURLsTableMgr.get(ctx, input.ID)
if err != nil {
return nil, err
}
utils.SortURLs(urls)
if err := studiosURLsTableMgr.replaceJoins(ctx, input.ID, urls); err != nil {
return nil, err
}
}
if err := qb.tagRelationshipStore.modifyRelationships(ctx, input.ID, input.TagIDs); err != nil {
@ -284,9 +272,7 @@ func (qb *StudioStore) Update(ctx context.Context, updatedObject *models.Studio)
}
if updatedObject.URLs.Loaded() {
urls := updatedObject.URLs.List()
utils.SortURLs(urls)
if err := studiosURLsTableMgr.replaceJoins(ctx, updatedObject.ID, urls); err != nil {
if err := studiosURLsTableMgr.replaceJoins(ctx, updatedObject.ID, updatedObject.URLs.List()); err != nil {
return err
}
}

View file

@ -1,10 +1,6 @@
package utils
import (
"regexp"
"sort"
"strings"
)
import "regexp"
// URLFromHandle adds the site URL to the input if the input is not already a URL
// siteURL must not end with a slash
@ -17,21 +13,3 @@ func URLFromHandle(input string, siteURL string) string {
return siteURL + "/" + input
}
// urlSortKey extracts the sortable portion of a URL by removing the protocol and www. prefix
func urlSortKey(url string) string {
// Remove http:// or https://
key := strings.TrimPrefix(url, "https://")
key = strings.TrimPrefix(key, "http://")
// Remove www. prefix
key = strings.TrimPrefix(key, "www.")
return strings.ToLower(key)
}
// SortURLs sorts a slice of URLs alphabetically by their base URL,
// excluding the protocol (http/https) and www. prefix
func SortURLs(urls []string) {
sort.SliceStable(urls, func(i, j int) bool {
return urlSortKey(urls[i]) < urlSortKey(urls[j])
})
}