mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Model refactor, part 2 (#4092)
* Move conversions into changesetTranslator * Improve mutation error messages * Use models.New and models.NewPartial everywhere * Replace getStashIDsFor functions * Remove ImageCreateInput * Remove unused parameters * Refactor matching functions --------- Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
@@ -169,11 +169,10 @@ func (i *Importer) populateStudio(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (i *Importer) createStudio(ctx context.Context, name string) (int, error) {
|
||||
newStudio := &models.Studio{
|
||||
Name: name,
|
||||
}
|
||||
newStudio := models.NewStudio()
|
||||
newStudio.Name = name
|
||||
|
||||
err := i.StudioWriter.Create(ctx, newStudio)
|
||||
err := i.StudioWriter.Create(ctx, &newStudio)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -279,7 +278,8 @@ func (i *Importer) populatePerformers(ctx context.Context) error {
|
||||
func (i *Importer) createPerformers(ctx context.Context, names []string) ([]*models.Performer, error) {
|
||||
var ret []*models.Performer
|
||||
for _, name := range names {
|
||||
newPerformer := *models.NewPerformer(name)
|
||||
newPerformer := models.NewPerformer()
|
||||
newPerformer.Name = name
|
||||
|
||||
err := i.PerformerWriter.Create(ctx, &newPerformer)
|
||||
if err != nil {
|
||||
@@ -338,9 +338,10 @@ func (i *Importer) populateMovies(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (i *Importer) createMovie(ctx context.Context, name string) (int, error) {
|
||||
newMovie := models.NewMovie(name)
|
||||
newMovie := models.NewMovie()
|
||||
newMovie.Name = name
|
||||
|
||||
err := i.MovieWriter.Create(ctx, newMovie)
|
||||
err := i.MovieWriter.Create(ctx, &newMovie)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -468,14 +469,15 @@ func importTags(ctx context.Context, tagWriter models.TagFinderCreator, names []
|
||||
func createTags(ctx context.Context, tagWriter models.TagCreator, names []string) ([]*models.Tag, error) {
|
||||
var ret []*models.Tag
|
||||
for _, name := range names {
|
||||
newTag := models.NewTag(name)
|
||||
newTag := models.NewTag()
|
||||
newTag.Name = name
|
||||
|
||||
err := tagWriter.Create(ctx, newTag)
|
||||
err := tagWriter.Create(ctx, &newTag)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret = append(ret, newTag)
|
||||
ret = append(ret, &newTag)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/stashapp/stash/pkg/file/video"
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
@@ -100,21 +99,17 @@ func (h *ScanHandler) Handle(ctx context.Context, f models.File, oldFile models.
|
||||
}
|
||||
} else {
|
||||
// create a new scene
|
||||
now := time.Now()
|
||||
newScene := &models.Scene{
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
newScene := models.NewScene()
|
||||
|
||||
logger.Infof("%s doesn't exist. Creating new scene...", f.Base().Path)
|
||||
|
||||
if err := h.CreatorUpdater.Create(ctx, newScene, []models.FileID{videoFile.ID}); err != nil {
|
||||
if err := h.CreatorUpdater.Create(ctx, &newScene, []models.FileID{videoFile.ID}); err != nil {
|
||||
return fmt.Errorf("creating new scene: %w", err)
|
||||
}
|
||||
|
||||
h.PluginCache.RegisterPostHooks(ctx, newScene.ID, plugin.SceneCreatePost, nil, nil)
|
||||
|
||||
existing = []*models.Scene{newScene}
|
||||
existing = []*models.Scene{&newScene}
|
||||
}
|
||||
|
||||
if oldFile != nil {
|
||||
@@ -162,7 +157,8 @@ func (h *ScanHandler) associateExisting(ctx context.Context, existing []*models.
|
||||
}
|
||||
|
||||
// update updated_at time
|
||||
if _, err := h.CreatorUpdater.UpdatePartial(ctx, s.ID, models.NewScenePartial()); err != nil {
|
||||
scenePartial := models.NewScenePartial()
|
||||
if _, err := h.CreatorUpdater.UpdatePartial(ctx, s.ID, scenePartial); err != nil {
|
||||
return fmt.Errorf("updating scene: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,32 +74,32 @@ func (u UpdateSet) UpdateInput() models.SceneUpdateInput {
|
||||
}
|
||||
|
||||
func AddPerformer(ctx context.Context, qb models.SceneUpdater, o *models.Scene, performerID int) error {
|
||||
_, err := qb.UpdatePartial(ctx, o.ID, models.ScenePartial{
|
||||
PerformerIDs: &models.UpdateIDs{
|
||||
IDs: []int{performerID},
|
||||
Mode: models.RelationshipUpdateModeAdd,
|
||||
},
|
||||
})
|
||||
scenePartial := models.NewScenePartial()
|
||||
scenePartial.PerformerIDs = &models.UpdateIDs{
|
||||
IDs: []int{performerID},
|
||||
Mode: models.RelationshipUpdateModeAdd,
|
||||
}
|
||||
_, err := qb.UpdatePartial(ctx, o.ID, scenePartial)
|
||||
return err
|
||||
}
|
||||
|
||||
func AddTag(ctx context.Context, qb models.SceneUpdater, o *models.Scene, tagID int) error {
|
||||
_, err := qb.UpdatePartial(ctx, o.ID, models.ScenePartial{
|
||||
TagIDs: &models.UpdateIDs{
|
||||
IDs: []int{tagID},
|
||||
Mode: models.RelationshipUpdateModeAdd,
|
||||
},
|
||||
})
|
||||
scenePartial := models.NewScenePartial()
|
||||
scenePartial.TagIDs = &models.UpdateIDs{
|
||||
IDs: []int{tagID},
|
||||
Mode: models.RelationshipUpdateModeAdd,
|
||||
}
|
||||
_, err := qb.UpdatePartial(ctx, o.ID, scenePartial)
|
||||
return err
|
||||
}
|
||||
|
||||
func AddGallery(ctx context.Context, qb models.SceneUpdater, o *models.Scene, galleryID int) error {
|
||||
_, err := qb.UpdatePartial(ctx, o.ID, models.ScenePartial{
|
||||
TagIDs: &models.UpdateIDs{
|
||||
IDs: []int{galleryID},
|
||||
Mode: models.RelationshipUpdateModeAdd,
|
||||
},
|
||||
})
|
||||
scenePartial := models.NewScenePartial()
|
||||
scenePartial.TagIDs = &models.UpdateIDs{
|
||||
IDs: []int{galleryID},
|
||||
Mode: models.RelationshipUpdateModeAdd,
|
||||
}
|
||||
_, err := qb.UpdatePartial(ctx, o.ID, scenePartial)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user