mirror of https://github.com/stashapp/stash.git
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
|
@ -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,34 +165,44 @@ 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)
|
||||
if err != nil {
|
||||
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", s.Path)
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err = updater.Update(repo.Scene(), t.ScreenshotSetter)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error updating scene: %w", err)
|
||||
}
|
||||
|
||||
as := ""
|
||||
title := updater.Partial.Title
|
||||
if title != nil {
|
||||
as = fmt.Sprintf(" as %s", title.String)
|
||||
}
|
||||
logger.Infof("Successfully identified %s%s using %s", s.Path, as, result.source.Name)
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// don't update anything if nothing was set
|
||||
if updater.IsEmpty() {
|
||||
logger.Infof("Nothing to set for %s", scene.Path)
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err = updater.Update(repo.Scene(), t.ScreenshotSetter)
|
||||
if err != nil {
|
||||
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)
|
||||
if !updater.IsEmpty() {
|
||||
updateInput := updater.UpdateInput()
|
||||
fields := utils.NotNilFields(updateInput, "json")
|
||||
t.SceneUpdatePostHookExecutor.ExecuteSceneUpdatePostHooks(ctx, updateInput, fields)
|
||||
}
|
||||
logger.Infof("Successfully identified %s%s using %s", scene.Path, as, result.source.Name)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -130,25 +130,23 @@ 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{
|
||||
DefaultOptions: j.input.Options,
|
||||
Sources: sources,
|
||||
ScreenshotSetter: &scene.PathsScreenshotSetter{
|
||||
Paths: instance.Paths,
|
||||
FileNamingAlgorithm: instance.Config.GetVideoFileNamingAlgorithm(),
|
||||
},
|
||||
SceneUpdatePostHookExecutor: j.postHookExecutor,
|
||||
}
|
||||
var taskError error
|
||||
j.progress.ExecuteTask("Identifying "+s.Path, func() {
|
||||
task := identify.SceneIdentifier{
|
||||
DefaultOptions: j.input.Options,
|
||||
Sources: sources,
|
||||
ScreenshotSetter: &scene.PathsScreenshotSetter{
|
||||
Paths: instance.Paths,
|
||||
FileNamingAlgorithm: instance.Config.GetVideoFileNamingAlgorithm(),
|
||||
},
|
||||
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()
|
||||
|
|
Loading…
Reference in New Issue