Fix bulk add movie to scenes and autotag transaction error (#2928)

* Fix bulk add movie to scene
* Fix already in transaction error for autotag
This commit is contained in:
WithoutPants 2022-09-19 14:52:40 +10:00 committed by GitHub
parent 648247aa00
commit 0359ce2ed8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 5 deletions

View File

@ -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)

View File

@ -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()

View File

@ -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

View File

@ -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],

View File

@ -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)
}
}