mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Fix SQL error when querying performers with missing aliases (#4894)
This commit is contained in:
@@ -744,6 +744,7 @@ func (qb *PerformerStore) QueryCount(ctx context.Context, performerFilter *model
|
|||||||
return query.executeCount(ctx)
|
return query.executeCount(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO - we need to provide a whitelist of possible values
|
||||||
func performerIsMissingCriterionHandler(qb *PerformerStore, isMissing *string) criterionHandlerFunc {
|
func performerIsMissingCriterionHandler(qb *PerformerStore, isMissing *string) criterionHandlerFunc {
|
||||||
return func(ctx context.Context, f *filterBuilder) {
|
return func(ctx context.Context, f *filterBuilder) {
|
||||||
if isMissing != nil && *isMissing != "" {
|
if isMissing != nil && *isMissing != "" {
|
||||||
@@ -756,6 +757,9 @@ func performerIsMissingCriterionHandler(qb *PerformerStore, isMissing *string) c
|
|||||||
case "stash_id":
|
case "stash_id":
|
||||||
performersStashIDsTableMgr.join(f, "performer_stash_ids", "performers.id")
|
performersStashIDsTableMgr.join(f, "performer_stash_ids", "performers.id")
|
||||||
f.addWhere("performer_stash_ids.performer_id IS NULL")
|
f.addWhere("performer_stash_ids.performer_id IS NULL")
|
||||||
|
case "aliases":
|
||||||
|
performersAliasesTableMgr.join(f, "", "performers.id")
|
||||||
|
f.addWhere("performer_aliases.alias IS NULL")
|
||||||
default:
|
default:
|
||||||
f.addWhere("(performers." + *isMissing + " IS NULL OR TRIM(performers." + *isMissing + ") = '')")
|
f.addWhere("(performers." + *isMissing + " IS NULL OR TRIM(performers." + *isMissing + ") = '')")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1760,14 +1760,17 @@ func verifyPerformersRating100(t *testing.T, ratingCriterion models.IntCriterion
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPerformerQueryIsMissingRating(t *testing.T) {
|
func performerQueryIsMissing(ctx context.Context, t *testing.T, m string) []*models.Performer {
|
||||||
withTxn(func(ctx context.Context) error {
|
|
||||||
isMissing := "rating"
|
|
||||||
performerFilter := models.PerformerFilterType{
|
performerFilter := models.PerformerFilterType{
|
||||||
IsMissing: &isMissing,
|
IsMissing: &m,
|
||||||
}
|
}
|
||||||
|
|
||||||
performers := queryPerformers(ctx, t, &performerFilter, nil)
|
return queryPerformers(ctx, t, &performerFilter, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPerformerQueryIsMissingRating(t *testing.T) {
|
||||||
|
withTxn(func(ctx context.Context) error {
|
||||||
|
performers := performerQueryIsMissing(ctx, t, "rating")
|
||||||
|
|
||||||
assert.True(t, len(performers) > 0)
|
assert.True(t, len(performers) > 0)
|
||||||
|
|
||||||
@@ -1781,16 +1784,7 @@ func TestPerformerQueryIsMissingRating(t *testing.T) {
|
|||||||
|
|
||||||
func TestPerformerQueryIsMissingImage(t *testing.T) {
|
func TestPerformerQueryIsMissingImage(t *testing.T) {
|
||||||
withTxn(func(ctx context.Context) error {
|
withTxn(func(ctx context.Context) error {
|
||||||
isMissing := "image"
|
performers := performerQueryIsMissing(ctx, t, "image")
|
||||||
performerFilter := &models.PerformerFilterType{
|
|
||||||
IsMissing: &isMissing,
|
|
||||||
}
|
|
||||||
|
|
||||||
// ensure query does not error
|
|
||||||
performers, _, err := db.Performer.Query(ctx, performerFilter, nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Error querying performers: %s", err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.True(t, len(performers) > 0)
|
assert.True(t, len(performers) > 0)
|
||||||
|
|
||||||
@@ -1806,6 +1800,24 @@ func TestPerformerQueryIsMissingImage(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPerformerQueryIsMissingAlias(t *testing.T) {
|
||||||
|
withTxn(func(ctx context.Context) error {
|
||||||
|
performers := performerQueryIsMissing(ctx, t, "aliases")
|
||||||
|
|
||||||
|
assert.True(t, len(performers) > 0)
|
||||||
|
|
||||||
|
for _, performer := range performers {
|
||||||
|
a, err := db.Performer.GetAliases(ctx, performer.ID)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("error getting performer aliases: %s", err.Error())
|
||||||
|
}
|
||||||
|
assert.Nil(t, a)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestPerformerQuerySortScenesCount(t *testing.T) {
|
func TestPerformerQuerySortScenesCount(t *testing.T) {
|
||||||
sort := "scenes_count"
|
sort := "scenes_count"
|
||||||
direction := models.SortDirectionEnumDesc
|
direction := models.SortDirectionEnumDesc
|
||||||
|
|||||||
@@ -1420,6 +1420,14 @@ func performerStashID(i int) models.StashID {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func performerAliases(i int) []string {
|
||||||
|
if i%5 == 0 {
|
||||||
|
return []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
return []string{getPerformerStringValue(i, "alias")}
|
||||||
|
}
|
||||||
|
|
||||||
// createPerformers creates n performers with plain Name and o performers with camel cased NaMe included
|
// createPerformers creates n performers with plain Name and o performers with camel cased NaMe included
|
||||||
func createPerformers(ctx context.Context, n int, o int) error {
|
func createPerformers(ctx context.Context, n int, o int) error {
|
||||||
pqb := db.Performer
|
pqb := db.Performer
|
||||||
@@ -1443,7 +1451,7 @@ func createPerformers(ctx context.Context, n int, o int) error {
|
|||||||
performer := models.Performer{
|
performer := models.Performer{
|
||||||
Name: getPerformerStringValue(index, name),
|
Name: getPerformerStringValue(index, name),
|
||||||
Disambiguation: getPerformerStringValue(index, "disambiguation"),
|
Disambiguation: getPerformerStringValue(index, "disambiguation"),
|
||||||
Aliases: models.NewRelatedStrings([]string{getPerformerStringValue(index, "alias")}),
|
Aliases: models.NewRelatedStrings(performerAliases(index)),
|
||||||
URL: getPerformerNullStringValue(i, urlField),
|
URL: getPerformerNullStringValue(i, urlField),
|
||||||
Favorite: getPerformerBoolValue(i),
|
Favorite: getPerformerBoolValue(i),
|
||||||
Birthdate: getPerformerBirthdate(i),
|
Birthdate: getPerformerBirthdate(i),
|
||||||
|
|||||||
Reference in New Issue
Block a user