Change performer height to be numeric (#3060)

* Make height an int. Add height_cm field
* Change UI to use height_cm
* Use number fields for height/weight
* Add migration note
This commit is contained in:
WithoutPants
2022-11-08 14:09:03 +11:00
committed by GitHub
parent b9e07ade92
commit d2743cf5fb
35 changed files with 432 additions and 99 deletions

View File

@@ -2,6 +2,7 @@ package api
import (
"context"
"strconv"
"github.com/stashapp/stash/internal/api/urlbuilders"
"github.com/stashapp/stash/pkg/gallery"
@@ -9,6 +10,18 @@ import (
"github.com/stashapp/stash/pkg/models"
)
func (r *performerResolver) Height(ctx context.Context, obj *models.Performer) (*string, error) {
if obj.Height != nil {
ret := strconv.Itoa(*obj.Height)
return &ret, nil
}
return nil, nil
}
func (r *performerResolver) HeightCm(ctx context.Context, obj *models.Performer) (*int, error) {
return obj.Height, nil
}
func (r *performerResolver) Birthdate(ctx context.Context, obj *models.Performer) (*string, error) {
if obj.Birthdate != nil {
ret := obj.Birthdate.String()

View File

@@ -77,8 +77,15 @@ func (r *mutationResolver) PerformerCreate(ctx context.Context, input PerformerC
if input.EyeColor != nil {
newPerformer.EyeColor = *input.EyeColor
}
if input.Height != nil {
newPerformer.Height = *input.Height
// prefer height_cm over height
if input.HeightCm != nil {
newPerformer.Height = input.HeightCm
} else if input.Height != nil {
h, err := strconv.Atoi(*input.Height)
if err != nil {
return nil, fmt.Errorf("invalid height: %s", *input.Height)
}
newPerformer.Height = &h
}
if input.Measurements != nil {
newPerformer.Measurements = *input.Measurements
@@ -213,7 +220,16 @@ func (r *mutationResolver) PerformerUpdate(ctx context.Context, input PerformerU
updatedPerformer.Country = translator.optionalString(input.Country, "country")
updatedPerformer.EyeColor = translator.optionalString(input.EyeColor, "eye_color")
updatedPerformer.Measurements = translator.optionalString(input.Measurements, "measurements")
updatedPerformer.Height = translator.optionalString(input.Height, "height")
// prefer height_cm over height
if translator.hasField("height_cm") {
updatedPerformer.Height = translator.optionalInt(input.HeightCm, "height_cm")
} else if translator.hasField("height") {
updatedPerformer.Height, err = translator.optionalIntFromString(input.Height, "height")
if err != nil {
return nil, err
}
}
updatedPerformer.Ethnicity = translator.optionalString(input.Ethnicity, "ethnicity")
updatedPerformer.FakeTits = translator.optionalString(input.FakeTits, "fake_tits")
updatedPerformer.CareerLength = translator.optionalString(input.CareerLength, "career_length")
@@ -317,7 +333,16 @@ func (r *mutationResolver) BulkPerformerUpdate(ctx context.Context, input BulkPe
updatedPerformer.Ethnicity = translator.optionalString(input.Ethnicity, "ethnicity")
updatedPerformer.Country = translator.optionalString(input.Country, "country")
updatedPerformer.EyeColor = translator.optionalString(input.EyeColor, "eye_color")
updatedPerformer.Height = translator.optionalString(input.Height, "height")
// prefer height_cm over height
if translator.hasField("height_cm") {
updatedPerformer.Height = translator.optionalInt(input.HeightCm, "height_cm")
} else if translator.hasField("height") {
updatedPerformer.Height, err = translator.optionalIntFromString(input.Height, "height")
if err != nil {
return nil, err
}
}
updatedPerformer.Measurements = translator.optionalString(input.Measurements, "measurements")
updatedPerformer.FakeTits = translator.optionalString(input.FakeTits, "fake_tits")
updatedPerformer.CareerLength = translator.optionalString(input.CareerLength, "career_length")

View File

@@ -84,7 +84,16 @@ func scrapedToPerformerInput(performer *models.ScrapedPerformer) models.Performe
ret.HairColor = *performer.HairColor
}
if performer.Height != nil {
ret.Height = *performer.Height
h, err := strconv.Atoi(*performer.Height) // height is stored as an int
if err == nil {
ret.Height = &h
}
}
if performer.Weight != nil {
h, err := strconv.Atoi(*performer.Weight)
if err == nil {
ret.Weight = &h
}
}
if performer.Measurements != nil {
ret.Measurements = *performer.Measurements

View File

@@ -10,6 +10,7 @@ import (
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/models/mocks"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
@@ -233,7 +234,7 @@ func Test_scrapedToPerformerInput(t *testing.T) {
md5 := "b068931cc450442b63f5b3d276ea4297"
var stringValues []string
for i := 0; i < 16; i++ {
for i := 0; i < 17; i++ {
stringValues = append(stringValues, strconv.Itoa(i))
}
@@ -244,6 +245,12 @@ func Test_scrapedToPerformerInput(t *testing.T) {
return &ret
}
nextIntVal := func() *int {
ret := upTo
upTo = (upTo + 1) % len(stringValues)
return &ret
}
dateToDatePtr := func(d models.Date) *models.Date {
return &d
}
@@ -265,6 +272,7 @@ func Test_scrapedToPerformerInput(t *testing.T) {
EyeColor: nextVal(),
HairColor: nextVal(),
Height: nextVal(),
Weight: nextVal(),
Measurements: nextVal(),
FakeTits: nextVal(),
CareerLength: nextVal(),
@@ -284,7 +292,8 @@ func Test_scrapedToPerformerInput(t *testing.T) {
Country: *nextVal(),
EyeColor: *nextVal(),
HairColor: *nextVal(),
Height: *nextVal(),
Height: nextIntVal(),
Weight: nextIntVal(),
Measurements: *nextVal(),
FakeTits: *nextVal(),
CareerLength: *nextVal(),
@@ -314,9 +323,7 @@ func Test_scrapedToPerformerInput(t *testing.T) {
got.CreatedAt = time.Time{}
got.UpdatedAt = got.CreatedAt
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("scrapedToPerformerInput() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, got)
})
}
}

View File

@@ -3,6 +3,7 @@ package manager
import (
"context"
"fmt"
"strconv"
"time"
"github.com/stashapp/stash/pkg/hash/md5"
@@ -114,7 +115,16 @@ func (t *StashBoxPerformerTagTask) stashBoxPerformerTag(ctx context.Context) {
partial.Gender = models.NewOptionalString(*performer.Gender)
}
if performer.Height != nil && !excluded["height"] {
partial.Height = models.NewOptionalString(*performer.Height)
h, err := strconv.Atoi(*performer.Height)
if err == nil {
partial.Height = models.NewOptionalInt(h)
}
}
if performer.Weight != nil && !excluded["weight"] {
w, err := strconv.Atoi(*performer.Weight)
if err == nil {
partial.Weight = models.NewOptionalInt(w)
}
}
if performer.Instagram != nil && !excluded["instagram"] {
partial.Instagram = models.NewOptionalString(*performer.Instagram)
@@ -192,7 +202,8 @@ func (t *StashBoxPerformerTagTask) stashBoxPerformerTag(ctx context.Context) {
EyeColor: getString(performer.EyeColor),
FakeTits: getString(performer.FakeTits),
Gender: models.GenderEnum(getString(performer.Gender)),
Height: getString(performer.Height),
Height: getIntPtr(performer.Height),
Weight: getIntPtr(performer.Weight),
Instagram: getString(performer.Instagram),
Measurements: getString(performer.Measurements),
Name: *performer.Name,
@@ -261,3 +272,16 @@ func getString(val *string) string {
return *val
}
}
func getIntPtr(val *string) *int {
if val == nil {
return nil
} else {
v, err := strconv.Atoi(*val)
if err != nil {
return nil
}
return &v
}
}