diff --git a/internal/api/resolver_mutation_scene.go b/internal/api/resolver_mutation_scene.go index b09fad894..cb5ae820d 100644 --- a/internal/api/resolver_mutation_scene.go +++ b/internal/api/resolver_mutation_scene.go @@ -228,7 +228,7 @@ func (r *mutationResolver) BulkSceneUpdate(ctx context.Context, input BulkSceneU } // Save the movies - if translator.hasField("movies") { + if translator.hasField("movie_ids") { updatedScene.MovieIDs, err = translateSceneMovieIDs(*input.MovieIds) if err != nil { return nil, fmt.Errorf("converting movie ids: %w", err) diff --git a/internal/manager/repository.go b/internal/manager/repository.go index ea3eb04e0..9e666cb06 100644 --- a/internal/manager/repository.go +++ b/internal/manager/repository.go @@ -66,6 +66,10 @@ func (r *Repository) WithTxn(ctx context.Context, fn txn.TxnFunc) error { return txn.WithTxn(ctx, r, fn) } +func (r *Repository) WithDB(ctx context.Context, fn txn.TxnFunc) error { + return txn.WithDatabase(ctx, r, fn) +} + func sqliteRepository(d *sqlite.Database) Repository { txnRepo := d.TxnRepository() diff --git a/internal/manager/task_autotag.go b/internal/manager/task_autotag.go index 62edb6597..09086117a 100644 --- a/internal/manager/task_autotag.go +++ b/internal/manager/task_autotag.go @@ -124,7 +124,7 @@ func (j *autoTagJob) autoTagPerformers(ctx context.Context, progress *job.Progre for _, performerId := range performerIds { var performers []*models.Performer - if err := j.txnManager.WithTxn(ctx, func(ctx context.Context) error { + if err := j.txnManager.WithDB(ctx, func(ctx context.Context) error { performerQuery := j.txnManager.Performer ignoreAutoTag := false perPage := -1 @@ -200,7 +200,7 @@ func (j *autoTagJob) autoTagStudios(ctx context.Context, progress *job.Progress, for _, studioId := range studioIds { var studios []*models.Studio - if err := r.WithTxn(ctx, func(ctx context.Context) error { + if err := r.WithDB(ctx, func(ctx context.Context) error { studioQuery := r.Studio ignoreAutoTag := false perPage := -1 @@ -279,7 +279,7 @@ func (j *autoTagJob) autoTagTags(ctx context.Context, progress *job.Progress, pa for _, tagId := range tagIds { var tags []*models.Tag - if err := j.txnManager.WithTxn(ctx, func(ctx context.Context) error { + if err := j.txnManager.WithDB(ctx, func(ctx context.Context) error { tagQuery := r.Tag ignoreAutoTag := false perPage := -1 diff --git a/pkg/sqlite/scene_test.go b/pkg/sqlite/scene_test.go index 80fd901d6..b1702b0ec 100644 --- a/pkg/sqlite/scene_test.go +++ b/pkg/sqlite/scene_test.go @@ -791,6 +791,29 @@ func Test_sceneQueryBuilder_UpdatePartialRelationships(t *testing.T) { }, false, }, + { + "add movies to empty", + sceneIDs[sceneIdx1WithPerformer], + models.ScenePartial{ + MovieIDs: &models.UpdateMovieIDs{ + Movies: movieScenes, + Mode: models.RelationshipUpdateModeAdd, + }, + }, + models.Scene{ + Movies: models.NewRelatedMovies([]models.MoviesScenes{ + { + MovieID: movieIDs[movieIdxWithDupName], + SceneIndex: &sceneIndex, + }, + { + MovieID: movieIDs[movieIdxWithStudio], + SceneIndex: &sceneIndex2, + }, + }), + }, + false, + }, { "add stash ids", sceneIDs[sceneIdxWithSpacedName], diff --git a/pkg/sqlite/table.go b/pkg/sqlite/table.go index c0b08fa6b..438d1e7b8 100644 --- a/pkg/sqlite/table.go +++ b/pkg/sqlite/table.go @@ -442,11 +442,16 @@ func (t *scenesMoviesTable) addJoins(ctx context.Context, id int, v []models.Mov // only add values that are not already present var filtered []models.MoviesScenes for _, vv := range v { + found := false + for _, e := range fks { if vv.MovieID == e.MovieID { - continue + found = true + break } + } + if !found { filtered = append(filtered, vv) } }