2021-09-08 05:30:15 +00:00
|
|
|
//go:build integration
|
2021-01-18 01:23:20 +00:00
|
|
|
// +build integration
|
|
|
|
|
|
|
|
package sqlite_test
|
|
|
|
|
|
|
|
import (
|
2022-05-19 07:49:32 +00:00
|
|
|
"context"
|
2021-01-18 01:23:20 +00:00
|
|
|
"database/sql"
|
|
|
|
"fmt"
|
2022-04-04 10:03:39 +00:00
|
|
|
"math"
|
2021-03-10 01:25:51 +00:00
|
|
|
"strconv"
|
2021-01-18 01:23:20 +00:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2022-03-17 00:33:59 +00:00
|
|
|
"github.com/stashapp/stash/pkg/hash/md5"
|
2021-01-18 01:23:20 +00:00
|
|
|
"github.com/stashapp/stash/pkg/models"
|
2022-05-19 07:49:32 +00:00
|
|
|
"github.com/stashapp/stash/pkg/sqlite"
|
2021-01-18 01:23:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestPerformerFindBySceneID(t *testing.T) {
|
2022-05-19 07:49:32 +00:00
|
|
|
withTxn(func(ctx context.Context) error {
|
|
|
|
pqb := sqlite.PerformerReaderWriter
|
2021-01-18 01:23:20 +00:00
|
|
|
sceneID := sceneIDs[sceneIdxWithPerformer]
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
performers, err := pqb.FindBySceneID(ctx, sceneID)
|
2021-01-18 01:23:20 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error finding performer: %s", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, 1, len(performers))
|
|
|
|
performer := performers[0]
|
|
|
|
|
|
|
|
assert.Equal(t, getPerformerStringValue(performerIdxWithScene, "Name"), performer.Name.String)
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
performers, err = pqb.FindBySceneID(ctx, 0)
|
2021-01-18 01:23:20 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error finding performer: %s", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, 0, len(performers))
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPerformerFindByNames(t *testing.T) {
|
2021-03-01 02:30:40 +00:00
|
|
|
getNames := func(p []*models.Performer) []string {
|
|
|
|
var ret []string
|
|
|
|
for _, pp := range p {
|
|
|
|
ret = append(ret, pp.Name.String)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
withTxn(func(ctx context.Context) error {
|
2021-01-18 01:23:20 +00:00
|
|
|
var names []string
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
pqb := sqlite.PerformerReaderWriter
|
2021-01-18 01:23:20 +00:00
|
|
|
|
|
|
|
names = append(names, performerNames[performerIdxWithScene]) // find performers by names
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
performers, err := pqb.FindByNames(ctx, names, false)
|
2021-01-18 01:23:20 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error finding performers: %s", err.Error())
|
|
|
|
}
|
|
|
|
assert.Len(t, performers, 1)
|
|
|
|
assert.Equal(t, performerNames[performerIdxWithScene], performers[0].Name.String)
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
performers, err = pqb.FindByNames(ctx, names, true) // find performers by names nocase
|
2021-01-18 01:23:20 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error finding performers: %s", err.Error())
|
|
|
|
}
|
|
|
|
assert.Len(t, performers, 2) // performerIdxWithScene and performerIdxWithDupName
|
|
|
|
assert.Equal(t, strings.ToLower(performerNames[performerIdxWithScene]), strings.ToLower(performers[0].Name.String))
|
|
|
|
assert.Equal(t, strings.ToLower(performerNames[performerIdxWithScene]), strings.ToLower(performers[1].Name.String))
|
|
|
|
|
|
|
|
names = append(names, performerNames[performerIdx1WithScene]) // find performers by names ( 2 names )
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
performers, err = pqb.FindByNames(ctx, names, false)
|
2021-01-18 01:23:20 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error finding performers: %s", err.Error())
|
|
|
|
}
|
2021-03-01 02:30:40 +00:00
|
|
|
retNames := getNames(performers)
|
|
|
|
assert.Equal(t, names, retNames)
|
2021-01-18 01:23:20 +00:00
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
performers, err = pqb.FindByNames(ctx, names, true) // find performers by names ( 2 names nocase)
|
2021-01-18 01:23:20 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error finding performers: %s", err.Error())
|
|
|
|
}
|
2021-03-01 02:30:40 +00:00
|
|
|
retNames = getNames(performers)
|
|
|
|
assert.Equal(t, []string{
|
|
|
|
performerNames[performerIdxWithScene],
|
|
|
|
performerNames[performerIdx1WithScene],
|
|
|
|
performerNames[performerIdx1WithDupName],
|
|
|
|
performerNames[performerIdxWithDupName],
|
|
|
|
}, retNames)
|
2021-01-18 01:23:20 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-05-22 07:07:03 +00:00
|
|
|
func TestPerformerQueryEthnicityOr(t *testing.T) {
|
|
|
|
const performer1Idx = 1
|
|
|
|
const performer2Idx = 2
|
|
|
|
|
|
|
|
performer1Eth := getPerformerStringValue(performer1Idx, "Ethnicity")
|
|
|
|
performer2Eth := getPerformerStringValue(performer2Idx, "Ethnicity")
|
|
|
|
|
|
|
|
performerFilter := models.PerformerFilterType{
|
|
|
|
Ethnicity: &models.StringCriterionInput{
|
|
|
|
Value: performer1Eth,
|
|
|
|
Modifier: models.CriterionModifierEquals,
|
|
|
|
},
|
|
|
|
Or: &models.PerformerFilterType{
|
|
|
|
Ethnicity: &models.StringCriterionInput{
|
|
|
|
Value: performer2Eth,
|
|
|
|
Modifier: models.CriterionModifierEquals,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
withTxn(func(ctx context.Context) error {
|
|
|
|
sqb := sqlite.PerformerReaderWriter
|
2021-05-22 07:07:03 +00:00
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
performers := queryPerformers(ctx, t, sqb, &performerFilter, nil)
|
2021-05-22 07:07:03 +00:00
|
|
|
|
|
|
|
assert.Len(t, performers, 2)
|
|
|
|
assert.Equal(t, performer1Eth, performers[0].Ethnicity.String)
|
|
|
|
assert.Equal(t, performer2Eth, performers[1].Ethnicity.String)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPerformerQueryEthnicityAndRating(t *testing.T) {
|
|
|
|
const performerIdx = 1
|
|
|
|
performerEth := getPerformerStringValue(performerIdx, "Ethnicity")
|
|
|
|
performerRating := getRating(performerIdx)
|
|
|
|
|
|
|
|
performerFilter := models.PerformerFilterType{
|
|
|
|
Ethnicity: &models.StringCriterionInput{
|
|
|
|
Value: performerEth,
|
|
|
|
Modifier: models.CriterionModifierEquals,
|
|
|
|
},
|
|
|
|
And: &models.PerformerFilterType{
|
|
|
|
Rating: &models.IntCriterionInput{
|
|
|
|
Value: int(performerRating.Int64),
|
|
|
|
Modifier: models.CriterionModifierEquals,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
withTxn(func(ctx context.Context) error {
|
|
|
|
sqb := sqlite.PerformerReaderWriter
|
2021-05-22 07:07:03 +00:00
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
performers := queryPerformers(ctx, t, sqb, &performerFilter, nil)
|
2021-05-22 07:07:03 +00:00
|
|
|
|
|
|
|
assert.Len(t, performers, 1)
|
|
|
|
assert.Equal(t, performerEth, performers[0].Ethnicity.String)
|
|
|
|
assert.Equal(t, performerRating.Int64, performers[0].Rating.Int64)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-09-16 02:09:23 +00:00
|
|
|
func TestPerformerQueryEthnicityNotRating(t *testing.T) {
|
2021-05-22 07:07:03 +00:00
|
|
|
const performerIdx = 1
|
|
|
|
|
|
|
|
performerRating := getRating(performerIdx)
|
|
|
|
|
|
|
|
ethCriterion := models.StringCriterionInput{
|
|
|
|
Value: "performer_.*1_Ethnicity",
|
|
|
|
Modifier: models.CriterionModifierMatchesRegex,
|
|
|
|
}
|
|
|
|
|
|
|
|
ratingCriterion := models.IntCriterionInput{
|
|
|
|
Value: int(performerRating.Int64),
|
|
|
|
Modifier: models.CriterionModifierEquals,
|
|
|
|
}
|
|
|
|
|
|
|
|
performerFilter := models.PerformerFilterType{
|
|
|
|
Ethnicity: ðCriterion,
|
|
|
|
Not: &models.PerformerFilterType{
|
|
|
|
Rating: &ratingCriterion,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
withTxn(func(ctx context.Context) error {
|
|
|
|
sqb := sqlite.PerformerReaderWriter
|
2021-05-22 07:07:03 +00:00
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
performers := queryPerformers(ctx, t, sqb, &performerFilter, nil)
|
2021-05-22 07:07:03 +00:00
|
|
|
|
|
|
|
for _, performer := range performers {
|
|
|
|
verifyString(t, performer.Ethnicity.String, ethCriterion)
|
|
|
|
ratingCriterion.Modifier = models.CriterionModifierNotEquals
|
|
|
|
verifyInt64(t, performer.Rating, ratingCriterion)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPerformerIllegalQuery(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
const performerIdx = 1
|
|
|
|
subFilter := models.PerformerFilterType{
|
|
|
|
Ethnicity: &models.StringCriterionInput{
|
|
|
|
Value: getPerformerStringValue(performerIdx, "Ethnicity"),
|
|
|
|
Modifier: models.CriterionModifierEquals,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
performerFilter := &models.PerformerFilterType{
|
|
|
|
And: &subFilter,
|
|
|
|
Or: &subFilter,
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
withTxn(func(ctx context.Context) error {
|
|
|
|
sqb := sqlite.PerformerReaderWriter
|
2021-05-22 07:07:03 +00:00
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
_, _, err := sqb.Query(ctx, performerFilter, nil)
|
2021-05-22 07:07:03 +00:00
|
|
|
assert.NotNil(err)
|
|
|
|
|
|
|
|
performerFilter.Or = nil
|
|
|
|
performerFilter.Not = &subFilter
|
2022-05-19 07:49:32 +00:00
|
|
|
_, _, err = sqb.Query(ctx, performerFilter, nil)
|
2021-05-22 07:07:03 +00:00
|
|
|
assert.NotNil(err)
|
|
|
|
|
|
|
|
performerFilter.And = nil
|
|
|
|
performerFilter.Or = &subFilter
|
2022-05-19 07:49:32 +00:00
|
|
|
_, _, err = sqb.Query(ctx, performerFilter, nil)
|
2021-05-22 07:07:03 +00:00
|
|
|
assert.NotNil(err)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-04-04 10:03:39 +00:00
|
|
|
func TestPerformerQueryIgnoreAutoTag(t *testing.T) {
|
2022-05-19 07:49:32 +00:00
|
|
|
withTxn(func(ctx context.Context) error {
|
2022-04-04 10:03:39 +00:00
|
|
|
ignoreAutoTag := true
|
|
|
|
performerFilter := models.PerformerFilterType{
|
|
|
|
IgnoreAutoTag: &ignoreAutoTag,
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
sqb := sqlite.PerformerReaderWriter
|
2022-04-04 10:03:39 +00:00
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
performers := queryPerformers(ctx, t, sqb, &performerFilter, nil)
|
2022-04-04 10:03:39 +00:00
|
|
|
|
|
|
|
assert.Len(t, performers, int(math.Ceil(float64(totalPerformers)/5)))
|
|
|
|
for _, p := range performers {
|
|
|
|
assert.True(t, p.IgnoreAutoTag)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-04-26 02:51:31 +00:00
|
|
|
func TestPerformerQueryForAutoTag(t *testing.T) {
|
2022-05-19 07:49:32 +00:00
|
|
|
withTxn(func(ctx context.Context) error {
|
|
|
|
tqb := sqlite.PerformerReaderWriter
|
2021-04-26 02:51:31 +00:00
|
|
|
|
2022-04-04 10:03:39 +00:00
|
|
|
name := performerNames[performerIdx1WithScene] // find a performer by name
|
2021-04-26 02:51:31 +00:00
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
performers, err := tqb.QueryForAutoTag(ctx, []string{name})
|
2021-04-26 02:51:31 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error finding performers: %s", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Len(t, performers, 2)
|
2022-04-04 10:03:39 +00:00
|
|
|
assert.Equal(t, strings.ToLower(performerNames[performerIdx1WithScene]), strings.ToLower(performers[0].Name.String))
|
|
|
|
assert.Equal(t, strings.ToLower(performerNames[performerIdx1WithScene]), strings.ToLower(performers[1].Name.String))
|
2021-04-26 02:51:31 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-01-18 01:23:20 +00:00
|
|
|
func TestPerformerUpdatePerformerImage(t *testing.T) {
|
2022-05-19 07:49:32 +00:00
|
|
|
if err := withTxn(func(ctx context.Context) error {
|
|
|
|
qb := sqlite.PerformerReaderWriter
|
2021-01-18 01:23:20 +00:00
|
|
|
|
|
|
|
// create performer to test against
|
|
|
|
const name = "TestPerformerUpdatePerformerImage"
|
|
|
|
performer := models.Performer{
|
|
|
|
Name: sql.NullString{String: name, Valid: true},
|
2022-03-17 00:33:59 +00:00
|
|
|
Checksum: md5.FromString(name),
|
2021-01-18 01:23:20 +00:00
|
|
|
Favorite: sql.NullBool{Bool: false, Valid: true},
|
|
|
|
}
|
2022-05-19 07:49:32 +00:00
|
|
|
created, err := qb.Create(ctx, performer)
|
2021-01-18 01:23:20 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error creating performer: %s", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
image := []byte("image")
|
2022-05-19 07:49:32 +00:00
|
|
|
err = qb.UpdateImage(ctx, created.ID, image)
|
2021-01-18 01:23:20 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error updating performer image: %s", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure image set
|
2022-05-19 07:49:32 +00:00
|
|
|
storedImage, err := qb.GetImage(ctx, created.ID)
|
2021-01-18 01:23:20 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error getting image: %s", err.Error())
|
|
|
|
}
|
|
|
|
assert.Equal(t, storedImage, image)
|
|
|
|
|
|
|
|
// set nil image
|
2022-05-19 07:49:32 +00:00
|
|
|
err = qb.UpdateImage(ctx, created.ID, nil)
|
2021-01-18 01:23:20 +00:00
|
|
|
if err == nil {
|
|
|
|
return fmt.Errorf("Expected error setting nil image")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}); err != nil {
|
|
|
|
t.Error(err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPerformerDestroyPerformerImage(t *testing.T) {
|
2022-05-19 07:49:32 +00:00
|
|
|
if err := withTxn(func(ctx context.Context) error {
|
|
|
|
qb := sqlite.PerformerReaderWriter
|
2021-01-18 01:23:20 +00:00
|
|
|
|
|
|
|
// create performer to test against
|
|
|
|
const name = "TestPerformerDestroyPerformerImage"
|
|
|
|
performer := models.Performer{
|
|
|
|
Name: sql.NullString{String: name, Valid: true},
|
2022-03-17 00:33:59 +00:00
|
|
|
Checksum: md5.FromString(name),
|
2021-01-18 01:23:20 +00:00
|
|
|
Favorite: sql.NullBool{Bool: false, Valid: true},
|
|
|
|
}
|
2022-05-19 07:49:32 +00:00
|
|
|
created, err := qb.Create(ctx, performer)
|
2021-01-18 01:23:20 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error creating performer: %s", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
image := []byte("image")
|
2022-05-19 07:49:32 +00:00
|
|
|
err = qb.UpdateImage(ctx, created.ID, image)
|
2021-01-18 01:23:20 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error updating performer image: %s", err.Error())
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
err = qb.DestroyImage(ctx, created.ID)
|
2021-01-18 01:23:20 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error destroying performer image: %s", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
// image should be nil
|
2022-05-19 07:49:32 +00:00
|
|
|
storedImage, err := qb.GetImage(ctx, created.ID)
|
2021-01-18 01:23:20 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error getting image: %s", err.Error())
|
|
|
|
}
|
|
|
|
assert.Nil(t, storedImage)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}); err != nil {
|
|
|
|
t.Error(err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPerformerQueryAge(t *testing.T) {
|
|
|
|
const age = 19
|
|
|
|
ageCriterion := models.IntCriterionInput{
|
|
|
|
Value: age,
|
|
|
|
Modifier: models.CriterionModifierEquals,
|
|
|
|
}
|
|
|
|
|
|
|
|
verifyPerformerAge(t, ageCriterion)
|
|
|
|
|
|
|
|
ageCriterion.Modifier = models.CriterionModifierNotEquals
|
|
|
|
verifyPerformerAge(t, ageCriterion)
|
|
|
|
|
|
|
|
ageCriterion.Modifier = models.CriterionModifierGreaterThan
|
|
|
|
verifyPerformerAge(t, ageCriterion)
|
|
|
|
|
|
|
|
ageCriterion.Modifier = models.CriterionModifierLessThan
|
|
|
|
verifyPerformerAge(t, ageCriterion)
|
|
|
|
}
|
|
|
|
|
|
|
|
func verifyPerformerAge(t *testing.T, ageCriterion models.IntCriterionInput) {
|
2022-05-19 07:49:32 +00:00
|
|
|
withTxn(func(ctx context.Context) error {
|
|
|
|
qb := sqlite.PerformerReaderWriter
|
2021-01-18 01:23:20 +00:00
|
|
|
performerFilter := models.PerformerFilterType{
|
|
|
|
Age: &ageCriterion,
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
performers, _, err := qb.Query(ctx, &performerFilter, nil)
|
2021-01-18 01:23:20 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error querying performer: %s", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
now := time.Now()
|
|
|
|
for _, performer := range performers {
|
2021-04-16 06:06:35 +00:00
|
|
|
cd := now
|
|
|
|
|
|
|
|
if performer.DeathDate.Valid {
|
|
|
|
cd, _ = time.Parse("2006-01-02", performer.DeathDate.String)
|
|
|
|
}
|
|
|
|
|
2021-01-18 01:23:20 +00:00
|
|
|
bd := performer.Birthdate.String
|
|
|
|
d, _ := time.Parse("2006-01-02", bd)
|
2021-04-16 06:06:35 +00:00
|
|
|
age := cd.Year() - d.Year()
|
|
|
|
if cd.YearDay() < d.YearDay() {
|
2021-01-18 01:23:20 +00:00
|
|
|
age = age - 1
|
|
|
|
}
|
|
|
|
|
|
|
|
verifyInt(t, age, ageCriterion)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-03-16 00:13:14 +00:00
|
|
|
func TestPerformerQueryCareerLength(t *testing.T) {
|
|
|
|
const value = "2005"
|
|
|
|
careerLengthCriterion := models.StringCriterionInput{
|
|
|
|
Value: value,
|
|
|
|
Modifier: models.CriterionModifierEquals,
|
|
|
|
}
|
|
|
|
|
|
|
|
verifyPerformerCareerLength(t, careerLengthCriterion)
|
|
|
|
|
|
|
|
careerLengthCriterion.Modifier = models.CriterionModifierNotEquals
|
|
|
|
verifyPerformerCareerLength(t, careerLengthCriterion)
|
|
|
|
|
|
|
|
careerLengthCriterion.Modifier = models.CriterionModifierMatchesRegex
|
|
|
|
verifyPerformerCareerLength(t, careerLengthCriterion)
|
|
|
|
|
|
|
|
careerLengthCriterion.Modifier = models.CriterionModifierNotMatchesRegex
|
|
|
|
verifyPerformerCareerLength(t, careerLengthCriterion)
|
|
|
|
}
|
|
|
|
|
|
|
|
func verifyPerformerCareerLength(t *testing.T, criterion models.StringCriterionInput) {
|
2022-05-19 07:49:32 +00:00
|
|
|
withTxn(func(ctx context.Context) error {
|
|
|
|
qb := sqlite.PerformerReaderWriter
|
2021-03-16 00:13:14 +00:00
|
|
|
performerFilter := models.PerformerFilterType{
|
|
|
|
CareerLength: &criterion,
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
performers, _, err := qb.Query(ctx, &performerFilter, nil)
|
2021-03-16 00:13:14 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error querying performer: %s", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, performer := range performers {
|
|
|
|
cl := performer.CareerLength
|
|
|
|
verifyNullString(t, cl, criterion)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-04-09 05:05:11 +00:00
|
|
|
func TestPerformerQueryURL(t *testing.T) {
|
|
|
|
const sceneIdx = 1
|
|
|
|
performerURL := getPerformerStringValue(sceneIdx, urlField)
|
|
|
|
|
|
|
|
urlCriterion := models.StringCriterionInput{
|
|
|
|
Value: performerURL,
|
|
|
|
Modifier: models.CriterionModifierEquals,
|
|
|
|
}
|
|
|
|
|
|
|
|
filter := models.PerformerFilterType{
|
|
|
|
URL: &urlCriterion,
|
|
|
|
}
|
|
|
|
|
|
|
|
verifyFn := func(g *models.Performer) {
|
|
|
|
t.Helper()
|
|
|
|
verifyNullString(t, g.URL, urlCriterion)
|
|
|
|
}
|
|
|
|
|
|
|
|
verifyPerformerQuery(t, filter, verifyFn)
|
|
|
|
|
|
|
|
urlCriterion.Modifier = models.CriterionModifierNotEquals
|
|
|
|
verifyPerformerQuery(t, filter, verifyFn)
|
|
|
|
|
|
|
|
urlCriterion.Modifier = models.CriterionModifierMatchesRegex
|
|
|
|
urlCriterion.Value = "performer_.*1_URL"
|
|
|
|
verifyPerformerQuery(t, filter, verifyFn)
|
|
|
|
|
|
|
|
urlCriterion.Modifier = models.CriterionModifierNotMatchesRegex
|
|
|
|
verifyPerformerQuery(t, filter, verifyFn)
|
|
|
|
|
|
|
|
urlCriterion.Modifier = models.CriterionModifierIsNull
|
|
|
|
urlCriterion.Value = ""
|
|
|
|
verifyPerformerQuery(t, filter, verifyFn)
|
|
|
|
|
|
|
|
urlCriterion.Modifier = models.CriterionModifierNotNull
|
|
|
|
verifyPerformerQuery(t, filter, verifyFn)
|
|
|
|
}
|
|
|
|
|
|
|
|
func verifyPerformerQuery(t *testing.T, filter models.PerformerFilterType, verifyFn func(s *models.Performer)) {
|
2022-05-19 07:49:32 +00:00
|
|
|
withTxn(func(ctx context.Context) error {
|
2021-04-09 05:05:11 +00:00
|
|
|
t.Helper()
|
2022-05-19 07:49:32 +00:00
|
|
|
sqb := sqlite.PerformerReaderWriter
|
2021-04-09 05:05:11 +00:00
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
performers := queryPerformers(ctx, t, sqb, &filter, nil)
|
2021-04-09 05:05:11 +00:00
|
|
|
|
|
|
|
// assume it should find at least one
|
|
|
|
assert.Greater(t, len(performers), 0)
|
|
|
|
|
|
|
|
for _, p := range performers {
|
|
|
|
verifyFn(p)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
func queryPerformers(ctx context.Context, t *testing.T, qb models.PerformerReader, performerFilter *models.PerformerFilterType, findFilter *models.FindFilterType) []*models.Performer {
|
|
|
|
performers, _, err := qb.Query(ctx, performerFilter, findFilter)
|
2021-03-10 01:25:51 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error querying performers: %s", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return performers
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPerformerQueryTags(t *testing.T) {
|
2022-05-19 07:49:32 +00:00
|
|
|
withTxn(func(ctx context.Context) error {
|
|
|
|
sqb := sqlite.PerformerReaderWriter
|
Tag hierarchy (#1519)
* Add migration script for tag relations table
* Expand hierarchical filter features
Expand the features of the hierarchical multi input filter with support
for using a relations table, which only has parent_id and child_id
columns, and support adding an additional intermediate table to join on,
for example for scenes and tags which are linked by the scenes_tags
table as well.
* Add hierarchical filtering for tags
* Add hierarchical tags support to scene markers
Refactor filtering of scene markers to filterBuilder and in the process
add support for hierarchical tags as well.
* List parent and child tags on tag details page
* Support setting parent and child tags
Add support for setting parent and child tags during tag creation and
tag updates.
* Validate no loops are created in tags hierarchy
* Update tag merging to support tag hierarcy
* Add unit tests for tags.EnsureUniqueHierarchy
* Fix applying recursive to with clause
The SQL `RECURSIVE` of a `WITH` clause only needs to be applied once,
imediately after the `WITH`. So this fixes the query building to do just
that, automatically applying the `RECURSIVE` keyword when any added with
clause is added as recursive.
* Rename hierarchical root id column
* Rewrite hierarchical filtering for performance
Completely rewrite the hierarchical filtering to optimize for
performance. Doing the recursive query in combination with a complex
query seems to break SQLite optimizing some things which means that the
recursive part might be 2,5 second slower than adding a static
`VALUES()` list. This is mostly noticable in case of the tag hierarchy
where setting an exclusion with any depth (or depth: all) being applied
has this performance impact of 2,5 second. "Include" also suffered this
issue, but some rewritten query by joining in the *_tags table in one
pass and applying a `WHERE x IS NOT NULL` filter did seem to optimize
that case. But that optimization isn't applied to the `IS NULL` filter
of "exclude". Running a simple query beforehand to get all (recursive)
items and then applying them to the query doesn't have this performance
penalty.
* Remove UI references to child studios and tags
* Add parents to tag export
* Support importing of parent relationship for tags
* Assign stable ids to parent / child badges
* Silence Apollo warning on parents/children fields on tags
Silence warning triggered by Apollo GraphQL by explicitly instructing it
to use the incoming parents/children values. By default it already does
this, but it triggers a warning as it might be unintended that it uses
the incoming values (instead of for example merging both arrays).
Setting merge to false still applies the same behaviour (use only
incoming values) but silences the warning as it's explicitly configured
to work like this.
* Rework detecting unique tag hierarchy
Completely rework the unique tag hierarchy to detect invalid hierarchies
for which a tag is "added in the middle". So when there are tags A <- B
and A <- C, you could previously edit tag B and add tag C as a sub tag
without it being noticed as parent A being applied twice (to tag C).
While afterwards saving tag C would fail as tag A was applied as parent
twice. The updated code correctly detects this scenario as well.
Furthermore the error messaging has been reworked a bit and the message
now mentions both the direct parent / sub tag as well as the tag which
would results in the error. So in aboves example it would now show the
message that tag C can't be applied because tag A already is a parent.
* Update relations on cached tags when needed
Update the relations on cached tags when a tag is created / updated /
deleted so these always reflect the correct state. Otherwise (re)opening
a tag might still show the old relations untill the page is fully
reloaded or the list is navigated. But this obviously is strange when
you for example have tag A, create or update tag B to have a relation to
tag A, and from tags B page click through to tag A and it doesn't show
that it is linked to tag B.
2021-09-09 04:58:43 +00:00
|
|
|
tagCriterion := models.HierarchicalMultiCriterionInput{
|
2021-03-10 01:25:51 +00:00
|
|
|
Value: []string{
|
|
|
|
strconv.Itoa(tagIDs[tagIdxWithPerformer]),
|
|
|
|
strconv.Itoa(tagIDs[tagIdx1WithPerformer]),
|
|
|
|
},
|
|
|
|
Modifier: models.CriterionModifierIncludes,
|
|
|
|
}
|
|
|
|
|
|
|
|
performerFilter := models.PerformerFilterType{
|
|
|
|
Tags: &tagCriterion,
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure ids are correct
|
2022-05-19 07:49:32 +00:00
|
|
|
performers := queryPerformers(ctx, t, sqb, &performerFilter, nil)
|
2021-03-10 01:25:51 +00:00
|
|
|
assert.Len(t, performers, 2)
|
|
|
|
for _, performer := range performers {
|
|
|
|
assert.True(t, performer.ID == performerIDs[performerIdxWithTag] || performer.ID == performerIDs[performerIdxWithTwoTags])
|
|
|
|
}
|
|
|
|
|
Tag hierarchy (#1519)
* Add migration script for tag relations table
* Expand hierarchical filter features
Expand the features of the hierarchical multi input filter with support
for using a relations table, which only has parent_id and child_id
columns, and support adding an additional intermediate table to join on,
for example for scenes and tags which are linked by the scenes_tags
table as well.
* Add hierarchical filtering for tags
* Add hierarchical tags support to scene markers
Refactor filtering of scene markers to filterBuilder and in the process
add support for hierarchical tags as well.
* List parent and child tags on tag details page
* Support setting parent and child tags
Add support for setting parent and child tags during tag creation and
tag updates.
* Validate no loops are created in tags hierarchy
* Update tag merging to support tag hierarcy
* Add unit tests for tags.EnsureUniqueHierarchy
* Fix applying recursive to with clause
The SQL `RECURSIVE` of a `WITH` clause only needs to be applied once,
imediately after the `WITH`. So this fixes the query building to do just
that, automatically applying the `RECURSIVE` keyword when any added with
clause is added as recursive.
* Rename hierarchical root id column
* Rewrite hierarchical filtering for performance
Completely rewrite the hierarchical filtering to optimize for
performance. Doing the recursive query in combination with a complex
query seems to break SQLite optimizing some things which means that the
recursive part might be 2,5 second slower than adding a static
`VALUES()` list. This is mostly noticable in case of the tag hierarchy
where setting an exclusion with any depth (or depth: all) being applied
has this performance impact of 2,5 second. "Include" also suffered this
issue, but some rewritten query by joining in the *_tags table in one
pass and applying a `WHERE x IS NOT NULL` filter did seem to optimize
that case. But that optimization isn't applied to the `IS NULL` filter
of "exclude". Running a simple query beforehand to get all (recursive)
items and then applying them to the query doesn't have this performance
penalty.
* Remove UI references to child studios and tags
* Add parents to tag export
* Support importing of parent relationship for tags
* Assign stable ids to parent / child badges
* Silence Apollo warning on parents/children fields on tags
Silence warning triggered by Apollo GraphQL by explicitly instructing it
to use the incoming parents/children values. By default it already does
this, but it triggers a warning as it might be unintended that it uses
the incoming values (instead of for example merging both arrays).
Setting merge to false still applies the same behaviour (use only
incoming values) but silences the warning as it's explicitly configured
to work like this.
* Rework detecting unique tag hierarchy
Completely rework the unique tag hierarchy to detect invalid hierarchies
for which a tag is "added in the middle". So when there are tags A <- B
and A <- C, you could previously edit tag B and add tag C as a sub tag
without it being noticed as parent A being applied twice (to tag C).
While afterwards saving tag C would fail as tag A was applied as parent
twice. The updated code correctly detects this scenario as well.
Furthermore the error messaging has been reworked a bit and the message
now mentions both the direct parent / sub tag as well as the tag which
would results in the error. So in aboves example it would now show the
message that tag C can't be applied because tag A already is a parent.
* Update relations on cached tags when needed
Update the relations on cached tags when a tag is created / updated /
deleted so these always reflect the correct state. Otherwise (re)opening
a tag might still show the old relations untill the page is fully
reloaded or the list is navigated. But this obviously is strange when
you for example have tag A, create or update tag B to have a relation to
tag A, and from tags B page click through to tag A and it doesn't show
that it is linked to tag B.
2021-09-09 04:58:43 +00:00
|
|
|
tagCriterion = models.HierarchicalMultiCriterionInput{
|
2021-03-10 01:25:51 +00:00
|
|
|
Value: []string{
|
|
|
|
strconv.Itoa(tagIDs[tagIdx1WithPerformer]),
|
|
|
|
strconv.Itoa(tagIDs[tagIdx2WithPerformer]),
|
|
|
|
},
|
|
|
|
Modifier: models.CriterionModifierIncludesAll,
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
performers = queryPerformers(ctx, t, sqb, &performerFilter, nil)
|
2021-03-10 01:25:51 +00:00
|
|
|
|
|
|
|
assert.Len(t, performers, 1)
|
|
|
|
assert.Equal(t, sceneIDs[performerIdxWithTwoTags], performers[0].ID)
|
|
|
|
|
Tag hierarchy (#1519)
* Add migration script for tag relations table
* Expand hierarchical filter features
Expand the features of the hierarchical multi input filter with support
for using a relations table, which only has parent_id and child_id
columns, and support adding an additional intermediate table to join on,
for example for scenes and tags which are linked by the scenes_tags
table as well.
* Add hierarchical filtering for tags
* Add hierarchical tags support to scene markers
Refactor filtering of scene markers to filterBuilder and in the process
add support for hierarchical tags as well.
* List parent and child tags on tag details page
* Support setting parent and child tags
Add support for setting parent and child tags during tag creation and
tag updates.
* Validate no loops are created in tags hierarchy
* Update tag merging to support tag hierarcy
* Add unit tests for tags.EnsureUniqueHierarchy
* Fix applying recursive to with clause
The SQL `RECURSIVE` of a `WITH` clause only needs to be applied once,
imediately after the `WITH`. So this fixes the query building to do just
that, automatically applying the `RECURSIVE` keyword when any added with
clause is added as recursive.
* Rename hierarchical root id column
* Rewrite hierarchical filtering for performance
Completely rewrite the hierarchical filtering to optimize for
performance. Doing the recursive query in combination with a complex
query seems to break SQLite optimizing some things which means that the
recursive part might be 2,5 second slower than adding a static
`VALUES()` list. This is mostly noticable in case of the tag hierarchy
where setting an exclusion with any depth (or depth: all) being applied
has this performance impact of 2,5 second. "Include" also suffered this
issue, but some rewritten query by joining in the *_tags table in one
pass and applying a `WHERE x IS NOT NULL` filter did seem to optimize
that case. But that optimization isn't applied to the `IS NULL` filter
of "exclude". Running a simple query beforehand to get all (recursive)
items and then applying them to the query doesn't have this performance
penalty.
* Remove UI references to child studios and tags
* Add parents to tag export
* Support importing of parent relationship for tags
* Assign stable ids to parent / child badges
* Silence Apollo warning on parents/children fields on tags
Silence warning triggered by Apollo GraphQL by explicitly instructing it
to use the incoming parents/children values. By default it already does
this, but it triggers a warning as it might be unintended that it uses
the incoming values (instead of for example merging both arrays).
Setting merge to false still applies the same behaviour (use only
incoming values) but silences the warning as it's explicitly configured
to work like this.
* Rework detecting unique tag hierarchy
Completely rework the unique tag hierarchy to detect invalid hierarchies
for which a tag is "added in the middle". So when there are tags A <- B
and A <- C, you could previously edit tag B and add tag C as a sub tag
without it being noticed as parent A being applied twice (to tag C).
While afterwards saving tag C would fail as tag A was applied as parent
twice. The updated code correctly detects this scenario as well.
Furthermore the error messaging has been reworked a bit and the message
now mentions both the direct parent / sub tag as well as the tag which
would results in the error. So in aboves example it would now show the
message that tag C can't be applied because tag A already is a parent.
* Update relations on cached tags when needed
Update the relations on cached tags when a tag is created / updated /
deleted so these always reflect the correct state. Otherwise (re)opening
a tag might still show the old relations untill the page is fully
reloaded or the list is navigated. But this obviously is strange when
you for example have tag A, create or update tag B to have a relation to
tag A, and from tags B page click through to tag A and it doesn't show
that it is linked to tag B.
2021-09-09 04:58:43 +00:00
|
|
|
tagCriterion = models.HierarchicalMultiCriterionInput{
|
2021-03-10 01:25:51 +00:00
|
|
|
Value: []string{
|
|
|
|
strconv.Itoa(tagIDs[tagIdx1WithPerformer]),
|
|
|
|
},
|
|
|
|
Modifier: models.CriterionModifierExcludes,
|
|
|
|
}
|
|
|
|
|
|
|
|
q := getSceneStringValue(performerIdxWithTwoTags, titleField)
|
|
|
|
findFilter := models.FindFilterType{
|
|
|
|
Q: &q,
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
performers = queryPerformers(ctx, t, sqb, &performerFilter, &findFilter)
|
2021-03-10 01:25:51 +00:00
|
|
|
assert.Len(t, performers, 0)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-04-09 08:46:00 +00:00
|
|
|
func TestPerformerQueryTagCount(t *testing.T) {
|
|
|
|
const tagCount = 1
|
|
|
|
tagCountCriterion := models.IntCriterionInput{
|
|
|
|
Value: tagCount,
|
|
|
|
Modifier: models.CriterionModifierEquals,
|
|
|
|
}
|
|
|
|
|
|
|
|
verifyPerformersTagCount(t, tagCountCriterion)
|
|
|
|
|
|
|
|
tagCountCriterion.Modifier = models.CriterionModifierNotEquals
|
|
|
|
verifyPerformersTagCount(t, tagCountCriterion)
|
|
|
|
|
|
|
|
tagCountCriterion.Modifier = models.CriterionModifierGreaterThan
|
|
|
|
verifyPerformersTagCount(t, tagCountCriterion)
|
|
|
|
|
|
|
|
tagCountCriterion.Modifier = models.CriterionModifierLessThan
|
|
|
|
verifyPerformersTagCount(t, tagCountCriterion)
|
|
|
|
}
|
|
|
|
|
|
|
|
func verifyPerformersTagCount(t *testing.T, tagCountCriterion models.IntCriterionInput) {
|
2022-05-19 07:49:32 +00:00
|
|
|
withTxn(func(ctx context.Context) error {
|
|
|
|
sqb := sqlite.PerformerReaderWriter
|
2021-04-09 08:46:00 +00:00
|
|
|
performerFilter := models.PerformerFilterType{
|
|
|
|
TagCount: &tagCountCriterion,
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
performers := queryPerformers(ctx, t, sqb, &performerFilter, nil)
|
2021-04-09 08:46:00 +00:00
|
|
|
assert.Greater(t, len(performers), 0)
|
|
|
|
|
|
|
|
for _, performer := range performers {
|
2022-05-19 07:49:32 +00:00
|
|
|
ids, err := sqb.GetTagIDs(ctx, performer.ID)
|
2021-04-09 08:46:00 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
verifyInt(t, len(ids), tagCountCriterion)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPerformerQuerySceneCount(t *testing.T) {
|
|
|
|
const sceneCount = 1
|
|
|
|
sceneCountCriterion := models.IntCriterionInput{
|
|
|
|
Value: sceneCount,
|
|
|
|
Modifier: models.CriterionModifierEquals,
|
|
|
|
}
|
|
|
|
|
|
|
|
verifyPerformersSceneCount(t, sceneCountCriterion)
|
|
|
|
|
|
|
|
sceneCountCriterion.Modifier = models.CriterionModifierNotEquals
|
|
|
|
verifyPerformersSceneCount(t, sceneCountCriterion)
|
|
|
|
|
|
|
|
sceneCountCriterion.Modifier = models.CriterionModifierGreaterThan
|
|
|
|
verifyPerformersSceneCount(t, sceneCountCriterion)
|
|
|
|
|
|
|
|
sceneCountCriterion.Modifier = models.CriterionModifierLessThan
|
|
|
|
verifyPerformersSceneCount(t, sceneCountCriterion)
|
|
|
|
}
|
|
|
|
|
|
|
|
func verifyPerformersSceneCount(t *testing.T, sceneCountCriterion models.IntCriterionInput) {
|
2022-05-19 07:49:32 +00:00
|
|
|
withTxn(func(ctx context.Context) error {
|
|
|
|
sqb := sqlite.PerformerReaderWriter
|
2021-04-09 08:46:00 +00:00
|
|
|
performerFilter := models.PerformerFilterType{
|
|
|
|
SceneCount: &sceneCountCriterion,
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
performers := queryPerformers(ctx, t, sqb, &performerFilter, nil)
|
2021-04-09 08:46:00 +00:00
|
|
|
assert.Greater(t, len(performers), 0)
|
|
|
|
|
|
|
|
for _, performer := range performers {
|
2022-07-13 06:30:54 +00:00
|
|
|
ids, err := db.Scene.FindByPerformerID(ctx, performer.ID)
|
2021-04-09 08:46:00 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
verifyInt(t, len(ids), sceneCountCriterion)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPerformerQueryImageCount(t *testing.T) {
|
|
|
|
const imageCount = 1
|
|
|
|
imageCountCriterion := models.IntCriterionInput{
|
|
|
|
Value: imageCount,
|
|
|
|
Modifier: models.CriterionModifierEquals,
|
|
|
|
}
|
|
|
|
|
|
|
|
verifyPerformersImageCount(t, imageCountCriterion)
|
|
|
|
|
|
|
|
imageCountCriterion.Modifier = models.CriterionModifierNotEquals
|
|
|
|
verifyPerformersImageCount(t, imageCountCriterion)
|
|
|
|
|
|
|
|
imageCountCriterion.Modifier = models.CriterionModifierGreaterThan
|
|
|
|
verifyPerformersImageCount(t, imageCountCriterion)
|
|
|
|
|
|
|
|
imageCountCriterion.Modifier = models.CriterionModifierLessThan
|
|
|
|
verifyPerformersImageCount(t, imageCountCriterion)
|
|
|
|
}
|
|
|
|
|
|
|
|
func verifyPerformersImageCount(t *testing.T, imageCountCriterion models.IntCriterionInput) {
|
2022-05-19 07:49:32 +00:00
|
|
|
withTxn(func(ctx context.Context) error {
|
|
|
|
sqb := sqlite.PerformerReaderWriter
|
2021-04-09 08:46:00 +00:00
|
|
|
performerFilter := models.PerformerFilterType{
|
|
|
|
ImageCount: &imageCountCriterion,
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
performers := queryPerformers(ctx, t, sqb, &performerFilter, nil)
|
2021-04-09 08:46:00 +00:00
|
|
|
assert.Greater(t, len(performers), 0)
|
|
|
|
|
|
|
|
for _, performer := range performers {
|
|
|
|
pp := 0
|
|
|
|
|
2022-07-13 06:30:54 +00:00
|
|
|
result, err := db.Image.Query(ctx, models.ImageQueryOptions{
|
2021-10-25 00:40:13 +00:00
|
|
|
QueryOptions: models.QueryOptions{
|
|
|
|
FindFilter: &models.FindFilterType{
|
|
|
|
PerPage: &pp,
|
|
|
|
},
|
|
|
|
Count: true,
|
|
|
|
},
|
|
|
|
ImageFilter: &models.ImageFilterType{
|
|
|
|
Performers: &models.MultiCriterionInput{
|
|
|
|
Value: []string{strconv.Itoa(performer.ID)},
|
|
|
|
Modifier: models.CriterionModifierIncludes,
|
|
|
|
},
|
2021-04-09 08:46:00 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-10-25 00:40:13 +00:00
|
|
|
verifyInt(t, result.Count, imageCountCriterion)
|
2021-04-09 08:46:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPerformerQueryGalleryCount(t *testing.T) {
|
|
|
|
const galleryCount = 1
|
|
|
|
galleryCountCriterion := models.IntCriterionInput{
|
|
|
|
Value: galleryCount,
|
|
|
|
Modifier: models.CriterionModifierEquals,
|
|
|
|
}
|
|
|
|
|
|
|
|
verifyPerformersGalleryCount(t, galleryCountCriterion)
|
|
|
|
|
|
|
|
galleryCountCriterion.Modifier = models.CriterionModifierNotEquals
|
|
|
|
verifyPerformersGalleryCount(t, galleryCountCriterion)
|
|
|
|
|
|
|
|
galleryCountCriterion.Modifier = models.CriterionModifierGreaterThan
|
|
|
|
verifyPerformersGalleryCount(t, galleryCountCriterion)
|
|
|
|
|
|
|
|
galleryCountCriterion.Modifier = models.CriterionModifierLessThan
|
|
|
|
verifyPerformersGalleryCount(t, galleryCountCriterion)
|
|
|
|
}
|
|
|
|
|
|
|
|
func verifyPerformersGalleryCount(t *testing.T, galleryCountCriterion models.IntCriterionInput) {
|
2022-05-19 07:49:32 +00:00
|
|
|
withTxn(func(ctx context.Context) error {
|
|
|
|
sqb := sqlite.PerformerReaderWriter
|
2021-04-09 08:46:00 +00:00
|
|
|
performerFilter := models.PerformerFilterType{
|
|
|
|
GalleryCount: &galleryCountCriterion,
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
performers := queryPerformers(ctx, t, sqb, &performerFilter, nil)
|
2021-04-09 08:46:00 +00:00
|
|
|
assert.Greater(t, len(performers), 0)
|
|
|
|
|
|
|
|
for _, performer := range performers {
|
|
|
|
pp := 0
|
|
|
|
|
2022-07-13 06:30:54 +00:00
|
|
|
_, count, err := db.Gallery.Query(ctx, &models.GalleryFilterType{
|
2021-04-09 08:46:00 +00:00
|
|
|
Performers: &models.MultiCriterionInput{
|
|
|
|
Value: []string{strconv.Itoa(performer.ID)},
|
|
|
|
Modifier: models.CriterionModifierIncludes,
|
|
|
|
},
|
|
|
|
}, &models.FindFilterType{
|
|
|
|
PerPage: &pp,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
verifyInt(t, count, galleryCountCriterion)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-05-22 07:07:03 +00:00
|
|
|
func TestPerformerQueryStudio(t *testing.T) {
|
2022-05-19 07:49:32 +00:00
|
|
|
withTxn(func(ctx context.Context) error {
|
2021-05-22 07:07:03 +00:00
|
|
|
testCases := []struct {
|
|
|
|
studioIndex int
|
|
|
|
performerIndex int
|
|
|
|
}{
|
|
|
|
{studioIndex: studioIdxWithScenePerformer, performerIndex: performerIdxWithSceneStudio},
|
|
|
|
{studioIndex: studioIdxWithImagePerformer, performerIndex: performerIdxWithImageStudio},
|
|
|
|
{studioIndex: studioIdxWithGalleryPerformer, performerIndex: performerIdxWithGalleryStudio},
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
sqb := sqlite.PerformerReaderWriter
|
2021-05-22 07:07:03 +00:00
|
|
|
|
|
|
|
for _, tc := range testCases {
|
2021-06-06 05:05:05 +00:00
|
|
|
studioCriterion := models.HierarchicalMultiCriterionInput{
|
2021-05-22 07:07:03 +00:00
|
|
|
Value: []string{
|
|
|
|
strconv.Itoa(studioIDs[tc.studioIndex]),
|
|
|
|
},
|
|
|
|
Modifier: models.CriterionModifierIncludes,
|
|
|
|
}
|
|
|
|
|
|
|
|
performerFilter := models.PerformerFilterType{
|
|
|
|
Studios: &studioCriterion,
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
performers := queryPerformers(ctx, t, sqb, &performerFilter, nil)
|
2021-05-22 07:07:03 +00:00
|
|
|
|
|
|
|
assert.Len(t, performers, 1)
|
|
|
|
|
|
|
|
// ensure id is correct
|
|
|
|
assert.Equal(t, performerIDs[tc.performerIndex], performers[0].ID)
|
|
|
|
|
2021-06-06 05:05:05 +00:00
|
|
|
studioCriterion = models.HierarchicalMultiCriterionInput{
|
2021-05-22 07:07:03 +00:00
|
|
|
Value: []string{
|
|
|
|
strconv.Itoa(studioIDs[tc.studioIndex]),
|
|
|
|
},
|
|
|
|
Modifier: models.CriterionModifierExcludes,
|
|
|
|
}
|
|
|
|
|
|
|
|
q := getPerformerStringValue(tc.performerIndex, "Name")
|
|
|
|
findFilter := models.FindFilterType{
|
|
|
|
Q: &q,
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
performers = queryPerformers(ctx, t, sqb, &performerFilter, &findFilter)
|
2021-05-22 07:07:03 +00:00
|
|
|
assert.Len(t, performers, 0)
|
|
|
|
}
|
|
|
|
|
2021-11-06 22:34:33 +00:00
|
|
|
// test NULL/not NULL
|
|
|
|
q := getPerformerStringValue(performerIdx1WithImage, "Name")
|
|
|
|
performerFilter := &models.PerformerFilterType{
|
|
|
|
Studios: &models.HierarchicalMultiCriterionInput{
|
|
|
|
Modifier: models.CriterionModifierIsNull,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
findFilter := &models.FindFilterType{
|
|
|
|
Q: &q,
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
performers := queryPerformers(ctx, t, sqb, performerFilter, findFilter)
|
2021-11-06 22:34:33 +00:00
|
|
|
assert.Len(t, performers, 1)
|
|
|
|
assert.Equal(t, imageIDs[performerIdx1WithImage], performers[0].ID)
|
|
|
|
|
|
|
|
q = getPerformerStringValue(performerIdxWithSceneStudio, "Name")
|
2022-05-19 07:49:32 +00:00
|
|
|
performers = queryPerformers(ctx, t, sqb, performerFilter, findFilter)
|
2021-11-06 22:34:33 +00:00
|
|
|
assert.Len(t, performers, 0)
|
|
|
|
|
|
|
|
performerFilter.Studios.Modifier = models.CriterionModifierNotNull
|
2022-05-19 07:49:32 +00:00
|
|
|
performers = queryPerformers(ctx, t, sqb, performerFilter, findFilter)
|
2021-11-06 22:34:33 +00:00
|
|
|
assert.Len(t, performers, 1)
|
|
|
|
assert.Equal(t, imageIDs[performerIdxWithSceneStudio], performers[0].ID)
|
|
|
|
|
|
|
|
q = getPerformerStringValue(performerIdx1WithImage, "Name")
|
2022-05-19 07:49:32 +00:00
|
|
|
performers = queryPerformers(ctx, t, sqb, performerFilter, findFilter)
|
2021-11-06 22:34:33 +00:00
|
|
|
assert.Len(t, performers, 0)
|
|
|
|
|
2021-05-22 07:07:03 +00:00
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-01-18 01:23:20 +00:00
|
|
|
func TestPerformerStashIDs(t *testing.T) {
|
2022-05-19 07:49:32 +00:00
|
|
|
if err := withTxn(func(ctx context.Context) error {
|
|
|
|
qb := sqlite.PerformerReaderWriter
|
2021-01-18 01:23:20 +00:00
|
|
|
|
|
|
|
// create performer to test against
|
|
|
|
const name = "TestStashIDs"
|
|
|
|
performer := models.Performer{
|
|
|
|
Name: sql.NullString{String: name, Valid: true},
|
2022-03-17 00:33:59 +00:00
|
|
|
Checksum: md5.FromString(name),
|
2021-01-18 01:23:20 +00:00
|
|
|
Favorite: sql.NullBool{Bool: false, Valid: true},
|
|
|
|
}
|
2022-05-19 07:49:32 +00:00
|
|
|
created, err := qb.Create(ctx, performer)
|
2021-01-18 01:23:20 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error creating performer: %s", err.Error())
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
testStashIDReaderWriter(ctx, t, qb, created.ID)
|
2021-01-18 01:23:20 +00:00
|
|
|
return nil
|
|
|
|
}); err != nil {
|
|
|
|
t.Error(err.Error())
|
|
|
|
}
|
|
|
|
}
|
2021-04-26 03:48:32 +00:00
|
|
|
func TestPerformerQueryRating(t *testing.T) {
|
|
|
|
const rating = 3
|
|
|
|
ratingCriterion := models.IntCriterionInput{
|
|
|
|
Value: rating,
|
|
|
|
Modifier: models.CriterionModifierEquals,
|
|
|
|
}
|
|
|
|
|
|
|
|
verifyPerformersRating(t, ratingCriterion)
|
|
|
|
|
|
|
|
ratingCriterion.Modifier = models.CriterionModifierNotEquals
|
|
|
|
verifyPerformersRating(t, ratingCriterion)
|
|
|
|
|
|
|
|
ratingCriterion.Modifier = models.CriterionModifierGreaterThan
|
|
|
|
verifyPerformersRating(t, ratingCriterion)
|
|
|
|
|
|
|
|
ratingCriterion.Modifier = models.CriterionModifierLessThan
|
|
|
|
verifyPerformersRating(t, ratingCriterion)
|
|
|
|
|
|
|
|
ratingCriterion.Modifier = models.CriterionModifierIsNull
|
|
|
|
verifyPerformersRating(t, ratingCriterion)
|
|
|
|
|
|
|
|
ratingCriterion.Modifier = models.CriterionModifierNotNull
|
|
|
|
verifyPerformersRating(t, ratingCriterion)
|
|
|
|
}
|
|
|
|
|
|
|
|
func verifyPerformersRating(t *testing.T, ratingCriterion models.IntCriterionInput) {
|
2022-05-19 07:49:32 +00:00
|
|
|
withTxn(func(ctx context.Context) error {
|
|
|
|
sqb := sqlite.PerformerReaderWriter
|
2021-04-26 03:48:32 +00:00
|
|
|
performerFilter := models.PerformerFilterType{
|
|
|
|
Rating: &ratingCriterion,
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
performers := queryPerformers(ctx, t, sqb, &performerFilter, nil)
|
2021-04-26 03:48:32 +00:00
|
|
|
|
|
|
|
for _, performer := range performers {
|
|
|
|
verifyInt64(t, performer.Rating, ratingCriterion)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPerformerQueryIsMissingRating(t *testing.T) {
|
2022-05-19 07:49:32 +00:00
|
|
|
withTxn(func(ctx context.Context) error {
|
|
|
|
sqb := sqlite.PerformerReaderWriter
|
2021-04-26 03:48:32 +00:00
|
|
|
isMissing := "rating"
|
|
|
|
performerFilter := models.PerformerFilterType{
|
|
|
|
IsMissing: &isMissing,
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
performers := queryPerformers(ctx, t, sqb, &performerFilter, nil)
|
2021-04-26 03:48:32 +00:00
|
|
|
|
|
|
|
assert.True(t, len(performers) > 0)
|
|
|
|
|
|
|
|
for _, performer := range performers {
|
|
|
|
assert.True(t, !performer.Rating.Valid)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
2021-01-18 01:23:20 +00:00
|
|
|
|
2021-05-24 07:45:51 +00:00
|
|
|
func TestPerformerQueryIsMissingImage(t *testing.T) {
|
2022-05-19 07:49:32 +00:00
|
|
|
withTxn(func(ctx context.Context) error {
|
2021-05-24 07:45:51 +00:00
|
|
|
isMissing := "image"
|
|
|
|
performerFilter := &models.PerformerFilterType{
|
|
|
|
IsMissing: &isMissing,
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure query does not error
|
2022-05-19 07:49:32 +00:00
|
|
|
performers, _, err := sqlite.PerformerReaderWriter.Query(ctx, performerFilter, nil)
|
2021-05-24 07:45:51 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error querying performers: %s", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, len(performers) > 0)
|
|
|
|
|
|
|
|
for _, performer := range performers {
|
2022-05-19 07:49:32 +00:00
|
|
|
img, err := sqlite.PerformerReaderWriter.GetImage(ctx, performer.ID)
|
2021-05-24 07:45:51 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("error getting performer image: %s", err.Error())
|
|
|
|
}
|
|
|
|
assert.Nil(t, img)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPerformerQuerySortScenesCount(t *testing.T) {
|
|
|
|
sort := "scenes_count"
|
|
|
|
direction := models.SortDirectionEnumDesc
|
|
|
|
findFilter := &models.FindFilterType{
|
|
|
|
Sort: &sort,
|
|
|
|
Direction: &direction,
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
withTxn(func(ctx context.Context) error {
|
2021-05-24 07:45:51 +00:00
|
|
|
// just ensure it queries without error
|
2022-05-19 07:49:32 +00:00
|
|
|
performers, _, err := sqlite.PerformerReaderWriter.Query(ctx, nil, findFilter)
|
2021-05-24 07:45:51 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error querying performers: %s", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, len(performers) > 0)
|
|
|
|
|
|
|
|
// first performer should be performerIdxWithTwoScenes
|
|
|
|
firstPerformer := performers[0]
|
|
|
|
|
|
|
|
assert.Equal(t, performerIDs[performerIdxWithTwoScenes], firstPerformer.ID)
|
|
|
|
|
|
|
|
// sort in ascending order
|
|
|
|
direction = models.SortDirectionEnumAsc
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
performers, _, err = sqlite.PerformerReaderWriter.Query(ctx, nil, findFilter)
|
2021-05-24 07:45:51 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error querying performers: %s", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, len(performers) > 0)
|
|
|
|
lastPerformer := performers[len(performers)-1]
|
|
|
|
|
|
|
|
assert.Equal(t, performerIDs[performerIdxWithTwoScenes], lastPerformer.ID)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-01-18 01:23:20 +00:00
|
|
|
// TODO Update
|
|
|
|
// TODO Destroy
|
|
|
|
// TODO Find
|
|
|
|
// TODO Count
|
|
|
|
// TODO All
|
|
|
|
// TODO AllSlim
|
|
|
|
// TODO Query
|