mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
Move scene post update hook to outside Identify transaction (#1953)
* Move update post hook call outside transaction * Make Scene Movies resolver use read transaction
This commit is contained in:
@@ -140,7 +140,7 @@ func (r *sceneResolver) Studio(ctx context.Context, obj *models.Scene) (ret *mod
|
||||
}
|
||||
|
||||
func (r *sceneResolver) Movies(ctx context.Context, obj *models.Scene) (ret []*models.SceneMovie, err error) {
|
||||
if err := r.withTxn(ctx, func(repo models.Repository) error {
|
||||
if err := r.withReadTxn(ctx, func(repo models.ReaderRepository) error {
|
||||
qb := repo.Scene()
|
||||
mqb := repo.Movie()
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ type SceneIdentifier struct {
|
||||
SceneUpdatePostHookExecutor SceneUpdatePostHookExecutor
|
||||
}
|
||||
|
||||
func (t *SceneIdentifier) Identify(ctx context.Context, repo models.Repository, scene *models.Scene) error {
|
||||
func (t *SceneIdentifier) Identify(ctx context.Context, txnManager models.TransactionManager, scene *models.Scene) error {
|
||||
result, err := t.scrapeScene(scene)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -45,7 +45,7 @@ func (t *SceneIdentifier) Identify(ctx context.Context, repo models.Repository,
|
||||
}
|
||||
|
||||
// results were found, modify the scene
|
||||
if err := t.modifyScene(ctx, repo, scene, result); err != nil {
|
||||
if err := t.modifyScene(ctx, txnManager, scene, result); err != nil {
|
||||
return fmt.Errorf("error modifying scene: %v", err)
|
||||
}
|
||||
|
||||
@@ -165,15 +165,18 @@ func (t *SceneIdentifier) getSceneUpdater(ctx context.Context, s *models.Scene,
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (t *SceneIdentifier) modifyScene(ctx context.Context, repo models.Repository, scene *models.Scene, result *scrapeResult) error {
|
||||
updater, err := t.getSceneUpdater(ctx, scene, result, repo)
|
||||
func (t *SceneIdentifier) modifyScene(ctx context.Context, txnManager models.TransactionManager, s *models.Scene, result *scrapeResult) error {
|
||||
var updater *scene.UpdateSet
|
||||
if err := txnManager.WithTxn(ctx, func(repo models.Repository) error {
|
||||
var err error
|
||||
updater, err = t.getSceneUpdater(ctx, s, result, repo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// don't update anything if nothing was set
|
||||
if updater.IsEmpty() {
|
||||
logger.Infof("Nothing to set for %s", scene.Path)
|
||||
logger.Infof("Nothing to set for %s", s.Path)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -182,17 +185,24 @@ func (t *SceneIdentifier) modifyScene(ctx context.Context, repo models.Repositor
|
||||
return fmt.Errorf("error updating scene: %w", err)
|
||||
}
|
||||
|
||||
// fire post-update hooks
|
||||
updateInput := updater.UpdateInput()
|
||||
fields := utils.NotNilFields(updateInput, "json")
|
||||
t.SceneUpdatePostHookExecutor.ExecuteSceneUpdatePostHooks(ctx, updateInput, fields)
|
||||
|
||||
as := ""
|
||||
title := updater.Partial.Title
|
||||
if title != nil {
|
||||
as = fmt.Sprintf(" as %s", title.String)
|
||||
}
|
||||
logger.Infof("Successfully identified %s%s using %s", scene.Path, as, result.source.Name)
|
||||
logger.Infof("Successfully identified %s%s using %s", s.Path, as, result.source.Name)
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// fire post-update hooks
|
||||
if !updater.IsEmpty() {
|
||||
updateInput := updater.UpdateInput()
|
||||
fields := utils.NotNilFields(updateInput, "json")
|
||||
t.SceneUpdatePostHookExecutor.ExecuteSceneUpdatePostHooks(ctx, updateInput, fields)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -130,7 +130,6 @@ func (j *IdentifyJob) identifyScene(ctx context.Context, s *models.Scene, source
|
||||
return
|
||||
}
|
||||
|
||||
if err := j.txnManager.WithTxn(context.TODO(), func(r models.Repository) error {
|
||||
var taskError error
|
||||
j.progress.ExecuteTask("Identifying "+s.Path, func() {
|
||||
task := identify.SceneIdentifier{
|
||||
@@ -143,12 +142,11 @@ func (j *IdentifyJob) identifyScene(ctx context.Context, s *models.Scene, source
|
||||
SceneUpdatePostHookExecutor: j.postHookExecutor,
|
||||
}
|
||||
|
||||
taskError = task.Identify(ctx, r, s)
|
||||
taskError = task.Identify(ctx, j.txnManager, s)
|
||||
})
|
||||
|
||||
return taskError
|
||||
}); err != nil {
|
||||
logger.Errorf("Error encountered identifying %s: %v", s.Path, err)
|
||||
if taskError != nil {
|
||||
logger.Errorf("Error encountered identifying %s: %v", s.Path, taskError)
|
||||
}
|
||||
|
||||
j.progress.Increment()
|
||||
|
||||
Reference in New Issue
Block a user