mirror of
https://github.com/stashapp/stash.git
synced 2025-12-07 17:02:38 +01: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:
parent
dbfd92f9a8
commit
5bb5f6f2ce
3 changed files with 51 additions and 43 deletions
|
|
@ -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) {
|
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()
|
qb := repo.Scene()
|
||||||
mqb := repo.Movie()
|
mqb := repo.Movie()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ type SceneIdentifier struct {
|
||||||
SceneUpdatePostHookExecutor SceneUpdatePostHookExecutor
|
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)
|
result, err := t.scrapeScene(scene)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -45,7 +45,7 @@ func (t *SceneIdentifier) Identify(ctx context.Context, repo models.Repository,
|
||||||
}
|
}
|
||||||
|
|
||||||
// results were found, modify the scene
|
// 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)
|
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
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *SceneIdentifier) modifyScene(ctx context.Context, repo models.Repository, scene *models.Scene, result *scrapeResult) error {
|
func (t *SceneIdentifier) modifyScene(ctx context.Context, txnManager models.TransactionManager, s *models.Scene, result *scrapeResult) error {
|
||||||
updater, err := t.getSceneUpdater(ctx, scene, result, repo)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't update anything if nothing was set
|
// don't update anything if nothing was set
|
||||||
if updater.IsEmpty() {
|
if updater.IsEmpty() {
|
||||||
logger.Infof("Nothing to set for %s", scene.Path)
|
logger.Infof("Nothing to set for %s", s.Path)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -182,17 +185,24 @@ func (t *SceneIdentifier) modifyScene(ctx context.Context, repo models.Repositor
|
||||||
return fmt.Errorf("error updating scene: %w", err)
|
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 := ""
|
as := ""
|
||||||
title := updater.Partial.Title
|
title := updater.Partial.Title
|
||||||
if title != nil {
|
if title != nil {
|
||||||
as = fmt.Sprintf(" as %s", title.String)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,6 @@ func (j *IdentifyJob) identifyScene(ctx context.Context, s *models.Scene, source
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := j.txnManager.WithTxn(context.TODO(), func(r models.Repository) error {
|
|
||||||
var taskError error
|
var taskError error
|
||||||
j.progress.ExecuteTask("Identifying "+s.Path, func() {
|
j.progress.ExecuteTask("Identifying "+s.Path, func() {
|
||||||
task := identify.SceneIdentifier{
|
task := identify.SceneIdentifier{
|
||||||
|
|
@ -143,12 +142,11 @@ func (j *IdentifyJob) identifyScene(ctx context.Context, s *models.Scene, source
|
||||||
SceneUpdatePostHookExecutor: j.postHookExecutor,
|
SceneUpdatePostHookExecutor: j.postHookExecutor,
|
||||||
}
|
}
|
||||||
|
|
||||||
taskError = task.Identify(ctx, r, s)
|
taskError = task.Identify(ctx, j.txnManager, s)
|
||||||
})
|
})
|
||||||
|
|
||||||
return taskError
|
if taskError != nil {
|
||||||
}); err != nil {
|
logger.Errorf("Error encountered identifying %s: %v", s.Path, taskError)
|
||||||
logger.Errorf("Error encountered identifying %s: %v", s.Path, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
j.progress.Increment()
|
j.progress.Increment()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue