mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
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:
@@ -228,7 +228,7 @@ func (r *mutationResolver) BulkSceneUpdate(ctx context.Context, input BulkSceneU
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save the movies
|
// Save the movies
|
||||||
if translator.hasField("movies") {
|
if translator.hasField("movie_ids") {
|
||||||
updatedScene.MovieIDs, err = translateSceneMovieIDs(*input.MovieIds)
|
updatedScene.MovieIDs, err = translateSceneMovieIDs(*input.MovieIds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("converting movie ids: %w", err)
|
return nil, fmt.Errorf("converting movie ids: %w", err)
|
||||||
|
|||||||
@@ -66,6 +66,10 @@ func (r *Repository) WithTxn(ctx context.Context, fn txn.TxnFunc) error {
|
|||||||
return txn.WithTxn(ctx, r, fn)
|
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 {
|
func sqliteRepository(d *sqlite.Database) Repository {
|
||||||
txnRepo := d.TxnRepository()
|
txnRepo := d.TxnRepository()
|
||||||
|
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ func (j *autoTagJob) autoTagPerformers(ctx context.Context, progress *job.Progre
|
|||||||
for _, performerId := range performerIds {
|
for _, performerId := range performerIds {
|
||||||
var performers []*models.Performer
|
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
|
performerQuery := j.txnManager.Performer
|
||||||
ignoreAutoTag := false
|
ignoreAutoTag := false
|
||||||
perPage := -1
|
perPage := -1
|
||||||
@@ -200,7 +200,7 @@ func (j *autoTagJob) autoTagStudios(ctx context.Context, progress *job.Progress,
|
|||||||
for _, studioId := range studioIds {
|
for _, studioId := range studioIds {
|
||||||
var studios []*models.Studio
|
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
|
studioQuery := r.Studio
|
||||||
ignoreAutoTag := false
|
ignoreAutoTag := false
|
||||||
perPage := -1
|
perPage := -1
|
||||||
@@ -279,7 +279,7 @@ func (j *autoTagJob) autoTagTags(ctx context.Context, progress *job.Progress, pa
|
|||||||
|
|
||||||
for _, tagId := range tagIds {
|
for _, tagId := range tagIds {
|
||||||
var tags []*models.Tag
|
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
|
tagQuery := r.Tag
|
||||||
ignoreAutoTag := false
|
ignoreAutoTag := false
|
||||||
perPage := -1
|
perPage := -1
|
||||||
|
|||||||
@@ -791,6 +791,29 @@ func Test_sceneQueryBuilder_UpdatePartialRelationships(t *testing.T) {
|
|||||||
},
|
},
|
||||||
false,
|
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",
|
"add stash ids",
|
||||||
sceneIDs[sceneIdxWithSpacedName],
|
sceneIDs[sceneIdxWithSpacedName],
|
||||||
|
|||||||
@@ -442,11 +442,16 @@ func (t *scenesMoviesTable) addJoins(ctx context.Context, id int, v []models.Mov
|
|||||||
// only add values that are not already present
|
// only add values that are not already present
|
||||||
var filtered []models.MoviesScenes
|
var filtered []models.MoviesScenes
|
||||||
for _, vv := range v {
|
for _, vv := range v {
|
||||||
|
found := false
|
||||||
|
|
||||||
for _, e := range fks {
|
for _, e := range fks {
|
||||||
if vv.MovieID == e.MovieID {
|
if vv.MovieID == e.MovieID {
|
||||||
continue
|
found = true
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !found {
|
||||||
filtered = append(filtered, vv)
|
filtered = append(filtered, vv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user