Movie group renames (#5039)

* Rename Movie and MoviePartial to Group/GroupPartial
* Rename Movie interfaces
* Update movie url builders to use group
* Rename movieRoutes to groupRoutes
* Update dataloader
* Update names in sqlite package
* Rename in resolvers
* Add GroupByURL to scraper config
* Scraper backward compatibility hacks
This commit is contained in:
WithoutPants
2024-07-04 09:10:26 +10:00
committed by GitHub
parent b69d9cc840
commit 15a7b8a859
83 changed files with 1765 additions and 1646 deletions

View File

@@ -54,7 +54,7 @@ const (
)
const (
sceneIdxWithMovie = iota
sceneIdxWithGroup = iota
sceneIdxWithGallery
sceneIdxWithPerformer
sceneIdx1WithPerformer
@@ -148,17 +148,17 @@ const (
)
const (
movieIdxWithScene = iota
movieIdxWithStudio
movieIdxWithTag
movieIdxWithTwoTags
movieIdxWithThreeTags
// movies with dup names start from the end
// create 7 more basic movies (can remove this if we add more indexes)
movieIdxWithDupName = movieIdxWithStudio + 7
groupIdxWithScene = iota
groupIdxWithStudio
groupIdxWithTag
groupIdxWithTwoTags
groupIdxWithThreeTags
// groups with dup names start from the end
// create 7 more basic groups (can remove this if we add more indexes)
groupIdxWithDupName = groupIdxWithStudio + 7
moviesNameCase = movieIdxWithDupName
moviesNameNoCase = 1
groupsNameCase = groupIdxWithDupName
groupsNameNoCase = 1
)
const (
@@ -220,10 +220,10 @@ const (
tagIdxWithParentAndChild
tagIdxWithGrandParent
tagIdx2WithMarkers
tagIdxWithMovie
tagIdx1WithMovie
tagIdx2WithMovie
tagIdx3WithMovie
tagIdxWithGroup
tagIdx1WithGroup
tagIdx2WithGroup
tagIdx3WithGroup
// new indexes above
// tags with dup names start from the end
tagIdx1WithDupName
@@ -238,7 +238,7 @@ const (
const (
studioIdxWithScene = iota
studioIdxWithTwoScenes
studioIdxWithMovie
studioIdxWithGroup
studioIdxWithChildStudio
studioIdxWithParentStudio
studioIdxWithImage
@@ -305,7 +305,7 @@ var (
sceneIDs []int
imageIDs []int
performerIDs []int
movieIDs []int
groupIDs []int
galleryIDs []int
tagIDs []int
studioIDs []int
@@ -316,7 +316,7 @@ var (
tagNames []string
studioNames []string
movieNames []string
groupNames []string
performerNames []string
)
@@ -389,8 +389,8 @@ var (
sceneIdxWithGallery: {galleryIdxWithScene},
}
sceneMovies = linkMap{
sceneIdxWithMovie: {movieIdxWithScene},
sceneGroups = linkMap{
sceneIdxWithGroup: {groupIdxWithScene},
}
sceneStudios = map[int]int{
@@ -496,14 +496,14 @@ var (
)
var (
movieStudioLinks = [][2]int{
{movieIdxWithStudio, studioIdxWithMovie},
groupStudioLinks = [][2]int{
{groupIdxWithStudio, studioIdxWithGroup},
}
movieTags = linkMap{
movieIdxWithTag: {tagIdxWithMovie},
movieIdxWithTwoTags: {tagIdx1WithMovie, tagIdx2WithMovie},
movieIdxWithThreeTags: {tagIdx1WithMovie, tagIdx2WithMovie, tagIdx3WithMovie},
groupTags = linkMap{
groupIdxWithTag: {tagIdxWithGroup},
groupIdxWithTwoTags: {tagIdx1WithGroup, tagIdx2WithGroup},
groupIdxWithThreeTags: {tagIdx1WithGroup, tagIdx2WithGroup, tagIdx3WithGroup},
}
)
@@ -653,8 +653,8 @@ func populateDB() error {
return fmt.Errorf("error creating tags: %s", err.Error())
}
if err := createMovies(ctx, db.Movie, moviesNameCase, moviesNameNoCase); err != nil {
return fmt.Errorf("error creating movies: %s", err.Error())
if err := createGroups(ctx, db.Group, groupsNameCase, groupsNameNoCase); err != nil {
return fmt.Errorf("error creating groups: %s", err.Error())
}
if err := createPerformers(ctx, performersNameCase, performersNameNoCase); err != nil {
@@ -685,8 +685,8 @@ func populateDB() error {
return fmt.Errorf("error creating saved filters: %s", err.Error())
}
if err := linkMovieStudios(ctx, db.Movie); err != nil {
return fmt.Errorf("error linking movie studios: %s", err.Error())
if err := linkGroupStudios(ctx, db.Group); err != nil {
return fmt.Errorf("error linking group studios: %s", err.Error())
}
if err := linkStudiosParent(ctx); err != nil {
@@ -1069,12 +1069,12 @@ func makeScene(i int) *models.Scene {
pids := indexesToIDs(performerIDs, scenePerformers[i])
tids := indexesToIDs(tagIDs, sceneTags[i])
mids := indexesToIDs(movieIDs, sceneMovies[i])
mids := indexesToIDs(groupIDs, sceneGroups[i])
movies := make([]models.MoviesScenes, len(mids))
groups := make([]models.GroupsScenes, len(mids))
for i, m := range mids {
movies[i] = models.MoviesScenes{
MovieID: m,
groups[i] = models.GroupsScenes{
GroupID: m,
}
}
@@ -1092,7 +1092,7 @@ func makeScene(i int) *models.Scene {
GalleryIDs: models.NewRelatedIDs(gids),
PerformerIDs: models.NewRelatedIDs(pids),
TagIDs: models.NewRelatedIDs(tids),
Movies: models.NewRelatedMovies(movies),
Groups: models.NewRelatedGroups(groups),
StashIDs: models.NewRelatedStashIDs([]models.StashID{
sceneStashID(i),
}),
@@ -1320,18 +1320,18 @@ func createGalleries(ctx context.Context, n int) error {
return nil
}
func getMovieStringValue(index int, field string) string {
return getPrefixedStringValue("movie", index, field)
func getGroupStringValue(index int, field string) string {
return getPrefixedStringValue("group", index, field)
}
func getMovieNullStringValue(index int, field string) string {
ret := getPrefixedNullStringValue("movie", index, field)
func getGroupNullStringValue(index int, field string) string {
ret := getPrefixedNullStringValue("group", index, field)
return ret.String
}
func getMovieEmptyString(index int, field string) string {
v := getPrefixedNullStringValue("movie", index, field)
func getGroupEmptyString(index int, field string) string {
v := getPrefixedNullStringValue("group", index, field)
if !v.Valid {
return ""
}
@@ -1339,8 +1339,8 @@ func getMovieEmptyString(index int, field string) string {
return v.String
}
// createMoviees creates n movies with plain Name and o movies with camel cased NaMe included
func createMovies(ctx context.Context, mqb models.MovieReaderWriter, n int, o int) error {
// createGroups creates n groups with plain Name and o groups with camel cased NaMe included
func createGroups(ctx context.Context, mqb models.GroupReaderWriter, n int, o int) error {
const namePlain = "Name"
const nameNoCase = "NaMe"
@@ -1348,31 +1348,31 @@ func createMovies(ctx context.Context, mqb models.MovieReaderWriter, n int, o in
index := i
name := namePlain
tids := indexesToIDs(tagIDs, movieTags[i])
tids := indexesToIDs(tagIDs, groupTags[i])
if i >= n { // i<n tags get normal names
name = nameNoCase // i>=n movies get dup names if case is not checked
name = nameNoCase // i>=n groups get dup names if case is not checked
index = n + o - (i + 1) // for the name to be the same the number (index) must be the same also
} // so count backwards to 0 as needed
// movies [ i ] and [ n + o - i - 1 ] should have similar names with only the Name!=NaMe part different
// groups [ i ] and [ n + o - i - 1 ] should have similar names with only the Name!=NaMe part different
name = getMovieStringValue(index, name)
movie := models.Movie{
name = getGroupStringValue(index, name)
group := models.Group{
Name: name,
URLs: models.NewRelatedStrings([]string{
getMovieEmptyString(i, urlField),
getGroupEmptyString(i, urlField),
}),
TagIDs: models.NewRelatedIDs(tids),
}
err := mqb.Create(ctx, &movie)
err := mqb.Create(ctx, &group)
if err != nil {
return fmt.Errorf("Error creating movie [%d] %v+: %s", i, movie, err.Error())
return fmt.Errorf("Error creating group [%d] %v+: %s", i, group, err.Error())
}
movieIDs = append(movieIDs, movie.ID)
movieNames = append(movieNames, movie.Name)
groupIDs = append(groupIDs, group.ID)
groupNames = append(groupNames, group.Name)
}
return nil
@@ -1709,7 +1709,7 @@ func createStudios(ctx context.Context, n int, o int) error {
TagIDs: models.NewRelatedIDs(tids),
}
// only add aliases for some scenes
if i == studioIdxWithMovie || i%5 == 0 {
if i == studioIdxWithGroup || i%5 == 0 {
alias := getStudioStringValue(i, "Alias")
studio.Aliases = models.NewRelatedStrings([]string{alias})
}
@@ -1842,12 +1842,12 @@ func doLinks(links [][2]int, fn func(idx1, idx2 int) error) error {
return nil
}
func linkMovieStudios(ctx context.Context, mqb models.MovieWriter) error {
return doLinks(movieStudioLinks, func(movieIndex, studioIndex int) error {
movie := models.MoviePartial{
func linkGroupStudios(ctx context.Context, mqb models.GroupWriter) error {
return doLinks(groupStudioLinks, func(groupIndex, studioIndex int) error {
group := models.GroupPartial{
StudioID: models.NewOptionalInt(studioIDs[studioIndex]),
}
_, err := mqb.UpdatePartial(ctx, movieIDs[movieIndex], movie)
_, err := mqb.UpdatePartial(ctx, groupIDs[groupIndex], group)
return err
})