Skip to content

Commit

Permalink
Use single transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
WithoutPants committed Oct 29, 2024
1 parent 4c61353 commit b820558
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions internal/manager/task_generate_interactive_heatmap_speed.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package manager
import (
"context"
"fmt"
"time"

"github.com/stashapp/stash/pkg/file/video"
"github.com/stashapp/stash/pkg/fsutil"
Expand Down Expand Up @@ -47,23 +46,19 @@ func (t *GenerateInteractiveHeatmapSpeedTask) Start(ctx context.Context) {
if err := r.WithTxn(ctx, func(ctx context.Context) error {
primaryFile := t.Scene.Files.Primary()
primaryFile.InteractiveSpeed = &median
qb := r.File
return qb.Update(ctx, primaryFile)
if err := r.File.Update(ctx, primaryFile); err != nil {
return fmt.Errorf("updating interactive speed for %s: %w", primaryFile.Path, err)
}

// update the scene UpdatedAt field
// NewScenePartial sets the UpdatedAt field to the current time
if _, err := r.Scene.UpdatePartial(ctx, t.Scene.ID, models.NewScenePartial()); err != nil {
return fmt.Errorf("updating UpdatedAt field for scene %d: %w", t.Scene.ID, err)
}
return nil
}); err != nil && ctx.Err() == nil {
logger.Error(err.Error())
}

if err := r.WithTxn(ctx, func(ctx context.Context) error {
qb := r.Scene
scenePartial := models.NewScenePartial()
now := time.Now()
scenePartial.UpdatedAt = models.NewOptionalTime(now)

_, err := qb.UpdatePartial(ctx, t.Scene.ID, scenePartial)
return err
}); err != nil && ctx.Err() == nil {
logger.Errorf("error updating %s after heatmap generation: %s", t.Scene.Path, err.Error())
}
}

func (t *GenerateInteractiveHeatmapSpeedTask) required() bool {
Expand Down

0 comments on commit b820558

Please sign in to comment.