diff --git a/internal/api/resolver_mutation_gallery.go b/internal/api/resolver_mutation_gallery.go index 664a3bbee71..cd654eec80a 100644 --- a/internal/api/resolver_mutation_gallery.go +++ b/internal/api/resolver_mutation_gallery.go @@ -6,7 +6,6 @@ import ( "fmt" "os" "strconv" - "time" "github.com/stashapp/stash/internal/manager" "github.com/stashapp/stash/pkg/file" @@ -41,15 +40,12 @@ func (r *mutationResolver) GalleryCreate(ctx context.Context, input GalleryCreat } // Populate a new gallery from the input - currentTime := time.Now() - newGallery := models.Gallery{ - Title: input.Title, - URL: translator.string(input.URL, "url"), - Details: translator.string(input.Details, "details"), - Rating: translator.ratingConversion(input.Rating, input.Rating100), - CreatedAt: currentTime, - UpdatedAt: currentTime, - } + newGallery := models.NewGallery() + + newGallery.Title = input.Title + newGallery.URL = translator.string(input.URL, "url") + newGallery.Details = translator.string(input.Details, "details") + newGallery.Rating = translator.ratingConversion(input.Rating, input.Rating100) var err error @@ -486,14 +482,12 @@ func (r *mutationResolver) GalleryChapterCreate(ctx context.Context, input Galle return nil, fmt.Errorf("converting gallery id: %w", err) } - currentTime := time.Now() - newChapter := models.GalleryChapter{ - Title: input.Title, - ImageIndex: input.ImageIndex, - GalleryID: galleryID, - CreatedAt: currentTime, - UpdatedAt: currentTime, - } + // Populate a new gallery chapter from the input + newChapter := models.NewGalleryChapter() + + newChapter.Title = input.Title + newChapter.ImageIndex = input.ImageIndex + newChapter.GalleryID = galleryID // Start the transaction and save the gallery chapter if err := r.withTxn(ctx, func(ctx context.Context) error { diff --git a/internal/api/resolver_mutation_movie.go b/internal/api/resolver_mutation_movie.go index e5f505b95db..348de658976 100644 --- a/internal/api/resolver_mutation_movie.go +++ b/internal/api/resolver_mutation_movie.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "strconv" - "time" "github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/plugin" @@ -30,18 +29,15 @@ func (r *mutationResolver) MovieCreate(ctx context.Context, input MovieCreateInp } // Populate a new movie from the input - currentTime := time.Now() - newMovie := models.Movie{ - Name: input.Name, - CreatedAt: currentTime, - UpdatedAt: currentTime, - Aliases: translator.string(input.Aliases, "aliases"), - Duration: input.Duration, - Rating: translator.ratingConversion(input.Rating, input.Rating100), - Director: translator.string(input.Director, "director"), - Synopsis: translator.string(input.Synopsis, "synopsis"), - URL: translator.string(input.URL, "url"), - } + newMovie := models.NewMovie() + + newMovie.Name = input.Name + newMovie.Aliases = translator.string(input.Aliases, "aliases") + newMovie.Duration = input.Duration + newMovie.Rating = translator.ratingConversion(input.Rating, input.Rating100) + newMovie.Director = translator.string(input.Director, "director") + newMovie.Synopsis = translator.string(input.Synopsis, "synopsis") + newMovie.URL = translator.string(input.URL, "url") var err error diff --git a/internal/api/resolver_mutation_performer.go b/internal/api/resolver_mutation_performer.go index 763b4e7bfac..d76a0a434cf 100644 --- a/internal/api/resolver_mutation_performer.go +++ b/internal/api/resolver_mutation_performer.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "strconv" - "time" "github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/performer" @@ -31,34 +30,31 @@ func (r *mutationResolver) PerformerCreate(ctx context.Context, input models.Per } // Populate a new performer from the input - currentTime := time.Now() - newPerformer := models.Performer{ - Name: input.Name, - Disambiguation: translator.string(input.Disambiguation, "disambiguation"), - URL: translator.string(input.URL, "url"), - Gender: input.Gender, - Ethnicity: translator.string(input.Ethnicity, "ethnicity"), - Country: translator.string(input.Country, "country"), - EyeColor: translator.string(input.EyeColor, "eye_color"), - Measurements: translator.string(input.Measurements, "measurements"), - FakeTits: translator.string(input.FakeTits, "fake_tits"), - PenisLength: input.PenisLength, - Circumcised: input.Circumcised, - CareerLength: translator.string(input.CareerLength, "career_length"), - Tattoos: translator.string(input.Tattoos, "tattoos"), - Piercings: translator.string(input.Piercings, "piercings"), - Twitter: translator.string(input.Twitter, "twitter"), - Instagram: translator.string(input.Instagram, "instagram"), - Favorite: translator.bool(input.Favorite, "favorite"), - Rating: translator.ratingConversion(input.Rating, input.Rating100), - Details: translator.string(input.Details, "details"), - HairColor: translator.string(input.HairColor, "hair_color"), - Weight: input.Weight, - IgnoreAutoTag: translator.bool(input.IgnoreAutoTag, "ignore_auto_tag"), - CreatedAt: currentTime, - UpdatedAt: currentTime, - StashIDs: models.NewRelatedStashIDs(input.StashIds), - } + newPerformer := models.NewPerformer() + + newPerformer.Name = input.Name + newPerformer.Disambiguation = translator.string(input.Disambiguation, "disambiguation") + newPerformer.URL = translator.string(input.URL, "url") + newPerformer.Gender = input.Gender + newPerformer.Ethnicity = translator.string(input.Ethnicity, "ethnicity") + newPerformer.Country = translator.string(input.Country, "country") + newPerformer.EyeColor = translator.string(input.EyeColor, "eye_color") + newPerformer.Measurements = translator.string(input.Measurements, "measurements") + newPerformer.FakeTits = translator.string(input.FakeTits, "fake_tits") + newPerformer.PenisLength = input.PenisLength + newPerformer.Circumcised = input.Circumcised + newPerformer.CareerLength = translator.string(input.CareerLength, "career_length") + newPerformer.Tattoos = translator.string(input.Tattoos, "tattoos") + newPerformer.Piercings = translator.string(input.Piercings, "piercings") + newPerformer.Twitter = translator.string(input.Twitter, "twitter") + newPerformer.Instagram = translator.string(input.Instagram, "instagram") + newPerformer.Favorite = translator.bool(input.Favorite, "favorite") + newPerformer.Rating = translator.ratingConversion(input.Rating, input.Rating100) + newPerformer.Details = translator.string(input.Details, "details") + newPerformer.HairColor = translator.string(input.HairColor, "hair_color") + newPerformer.Weight = input.Weight + newPerformer.IgnoreAutoTag = translator.bool(input.IgnoreAutoTag, "ignore_auto_tag") + newPerformer.StashIDs = models.NewRelatedStashIDs(input.StashIds) var err error diff --git a/internal/api/resolver_mutation_scene.go b/internal/api/resolver_mutation_scene.go index d19402fa129..1ad8ee6ed90 100644 --- a/internal/api/resolver_mutation_scene.go +++ b/internal/api/resolver_mutation_scene.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "strconv" - "time" "github.com/stashapp/stash/internal/manager" "github.com/stashapp/stash/pkg/file" @@ -40,15 +39,15 @@ func (r *mutationResolver) SceneCreate(ctx context.Context, input models.SceneCr } // Populate a new scene from the input - newScene := models.Scene{ - Title: translator.string(input.Title, "title"), - Code: translator.string(input.Code, "code"), - Details: translator.string(input.Details, "details"), - Director: translator.string(input.Director, "director"), - Rating: translator.ratingConversion(input.Rating, input.Rating100), - Organized: translator.bool(input.Organized, "organized"), - StashIDs: models.NewRelatedStashIDs(input.StashIds), - } + newScene := models.NewScene() + + newScene.Title = translator.string(input.Title, "title") + newScene.Code = translator.string(input.Code, "code") + newScene.Details = translator.string(input.Details, "details") + newScene.Director = translator.string(input.Director, "director") + newScene.Rating = translator.ratingConversion(input.Rating, input.Rating100) + newScene.Organized = translator.bool(input.Organized, "organized") + newScene.StashIDs = models.NewRelatedStashIDs(input.StashIds) newScene.Date, err = translator.datePtr(input.Date, "date") if err != nil { @@ -622,15 +621,13 @@ func (r *mutationResolver) SceneMarkerCreate(ctx context.Context, input SceneMar return nil, fmt.Errorf("converting primary tag id: %w", err) } - currentTime := time.Now() - newMarker := models.SceneMarker{ - Title: input.Title, - Seconds: input.Seconds, - PrimaryTagID: primaryTagID, - SceneID: sceneID, - CreatedAt: currentTime, - UpdatedAt: currentTime, - } + // Populate a new scene marker from the input + newMarker := models.NewSceneMarker() + + newMarker.Title = input.Title + newMarker.Seconds = input.Seconds + newMarker.PrimaryTagID = primaryTagID + newMarker.SceneID = sceneID tagIDs, err := stringslice.StringSliceToIntSlice(input.TagIds) if err != nil { diff --git a/internal/api/resolver_mutation_studio.go b/internal/api/resolver_mutation_studio.go index 8055096714d..dd163d62193 100644 --- a/internal/api/resolver_mutation_studio.go +++ b/internal/api/resolver_mutation_studio.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "strconv" - "time" "github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/plugin" @@ -31,18 +30,15 @@ func (r *mutationResolver) StudioCreate(ctx context.Context, input models.Studio } // Populate a new studio from the input - currentTime := time.Now() - newStudio := models.Studio{ - Name: input.Name, - CreatedAt: currentTime, - UpdatedAt: currentTime, - URL: translator.string(input.URL, "url"), - Rating: translator.ratingConversion(input.Rating, input.Rating100), - Details: translator.string(input.Details, "details"), - IgnoreAutoTag: translator.bool(input.IgnoreAutoTag, "ignore_auto_tag"), - Aliases: models.NewRelatedStrings(input.Aliases), - StashIDs: models.NewRelatedStashIDs(input.StashIds), - } + newStudio := models.NewStudio() + + newStudio.Name = input.Name + newStudio.URL = translator.string(input.URL, "url") + newStudio.Rating = translator.ratingConversion(input.Rating, input.Rating100) + newStudio.Details = translator.string(input.Details, "details") + newStudio.IgnoreAutoTag = translator.bool(input.IgnoreAutoTag, "ignore_auto_tag") + newStudio.Aliases = models.NewRelatedStrings(input.Aliases) + newStudio.StashIDs = models.NewRelatedStashIDs(input.StashIds) var err error @@ -102,17 +98,16 @@ func (r *mutationResolver) StudioUpdate(ctx context.Context, input models.Studio } // Populate studio from the input - updatedStudio := models.StudioPartial{ - ID: studioID, - Name: translator.optionalString(input.Name, "name"), - URL: translator.optionalString(input.URL, "url"), - Details: translator.optionalString(input.Details, "details"), - Rating: translator.optionalRatingConversion(input.Rating, input.Rating100), - IgnoreAutoTag: translator.optionalBool(input.IgnoreAutoTag, "ignore_auto_tag"), - Aliases: translator.updateStrings(input.Aliases, "aliases"), - StashIDs: translator.updateStashIDs(input.StashIds, "stash_ids"), - UpdatedAt: models.NewOptionalTime(time.Now()), - } + updatedStudio := models.NewStudioPartial() + + updatedStudio.ID = studioID + updatedStudio.Name = translator.optionalString(input.Name, "name") + updatedStudio.URL = translator.optionalString(input.URL, "url") + updatedStudio.Details = translator.optionalString(input.Details, "details") + updatedStudio.Rating = translator.optionalRatingConversion(input.Rating, input.Rating100) + updatedStudio.IgnoreAutoTag = translator.optionalBool(input.IgnoreAutoTag, "ignore_auto_tag") + updatedStudio.Aliases = translator.updateStrings(input.Aliases, "aliases") + updatedStudio.StashIDs = translator.updateStashIDs(input.StashIds, "stash_ids") updatedStudio.ParentID, err = translator.optionalIntFromString(input.ParentID, "parent_id") if err != nil { diff --git a/internal/api/resolver_mutation_tag.go b/internal/api/resolver_mutation_tag.go index 7494da53f99..71d5b8d43f9 100644 --- a/internal/api/resolver_mutation_tag.go +++ b/internal/api/resolver_mutation_tag.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "strconv" - "time" "github.com/stashapp/stash/pkg/logger" "github.com/stashapp/stash/pkg/models" @@ -31,14 +30,11 @@ func (r *mutationResolver) TagCreate(ctx context.Context, input TagCreateInput) } // Populate a new tag from the input - currentTime := time.Now() - newTag := models.Tag{ - Name: input.Name, - CreatedAt: currentTime, - UpdatedAt: currentTime, - Description: translator.string(input.Description, "description"), - IgnoreAutoTag: translator.bool(input.IgnoreAutoTag, "ignore_auto_tag"), - } + newTag := models.NewTag() + + newTag.Name = input.Name + newTag.Description = translator.string(input.Description, "description") + newTag.IgnoreAutoTag = translator.bool(input.IgnoreAutoTag, "ignore_auto_tag") var err error diff --git a/internal/autotag/studio.go b/internal/autotag/studio.go index ef5a6f0da9c..8312e0edf61 100644 --- a/internal/autotag/studio.go +++ b/internal/autotag/studio.go @@ -18,9 +18,8 @@ func addSceneStudio(ctx context.Context, sceneWriter models.SceneUpdater, o *mod } // set the studio id - scenePartial := models.ScenePartial{ - StudioID: models.NewOptionalInt(studioID), - } + scenePartial := models.NewScenePartial() + scenePartial.StudioID = models.NewOptionalInt(studioID) if _, err := sceneWriter.UpdatePartial(ctx, o.ID, scenePartial); err != nil { return false, err @@ -35,9 +34,8 @@ func addImageStudio(ctx context.Context, imageWriter models.ImageUpdater, i *mod } // set the studio id - imagePartial := models.ImagePartial{ - StudioID: models.NewOptionalInt(studioID), - } + imagePartial := models.NewImagePartial() + imagePartial.StudioID = models.NewOptionalInt(studioID) if _, err := imageWriter.UpdatePartial(ctx, i.ID, imagePartial); err != nil { return false, err @@ -52,9 +50,8 @@ func addGalleryStudio(ctx context.Context, galleryWriter GalleryFinderUpdater, o } // set the studio id - galleryPartial := models.GalleryPartial{ - StudioID: models.NewOptionalInt(studioID), - } + galleryPartial := models.NewGalleryPartial() + galleryPartial.StudioID = models.NewOptionalInt(studioID) if _, err := galleryWriter.UpdatePartial(ctx, o.ID, galleryPartial); err != nil { return false, err @@ -93,9 +90,8 @@ func (tagger *Tagger) StudioScenes(ctx context.Context, p *models.Studio, paths } // set the studio id - scenePartial := models.ScenePartial{ - StudioID: models.NewOptionalInt(p.ID), - } + scenePartial := models.NewScenePartial() + scenePartial.StudioID = models.NewOptionalInt(p.ID) if err := txn.WithTxn(ctx, tagger.TxnManager, func(ctx context.Context) error { _, err := rw.UpdatePartial(ctx, o.ID, scenePartial) @@ -124,9 +120,8 @@ func (tagger *Tagger) StudioImages(ctx context.Context, p *models.Studio, paths } // set the studio id - imagePartial := models.ImagePartial{ - StudioID: models.NewOptionalInt(p.ID), - } + imagePartial := models.NewImagePartial() + imagePartial.StudioID = models.NewOptionalInt(p.ID) if err := txn.WithTxn(ctx, tagger.TxnManager, func(ctx context.Context) error { _, err := rw.UpdatePartial(ctx, i.ID, imagePartial) @@ -155,9 +150,8 @@ func (tagger *Tagger) StudioGalleries(ctx context.Context, p *models.Studio, pat } // set the studio id - galleryPartial := models.GalleryPartial{ - StudioID: models.NewOptionalInt(p.ID), - } + galleryPartial := models.NewGalleryPartial() + galleryPartial.StudioID = models.NewOptionalInt(p.ID) if err := txn.WithTxn(ctx, tagger.TxnManager, func(ctx context.Context) error { _, err := rw.UpdatePartial(ctx, o.ID, galleryPartial) diff --git a/internal/identify/scene.go b/internal/identify/scene.go index 9a951c13b18..eec8ce6edc2 100644 --- a/internal/identify/scene.go +++ b/internal/identify/scene.go @@ -7,7 +7,6 @@ import ( "fmt" "strconv" "strings" - "time" "github.com/stashapp/stash/pkg/logger" "github.com/stashapp/stash/pkg/models" @@ -164,12 +163,9 @@ func (g sceneRelationships) tags(ctx context.Context) ([]int, error) { tagIDs = intslice.IntAppendUnique(tagIDs, int(tagID)) } else if createMissing { - now := time.Now() - newTag := models.Tag{ - Name: t.Name, - CreatedAt: now, - UpdatedAt: now, - } + newTag := models.NewTag() + newTag.Name = t.Name + err := g.tagCreator.Create(ctx, &newTag) if err != nil { return nil, fmt.Errorf("error creating tag: %w", err) diff --git a/internal/manager/task_clean.go b/internal/manager/task_clean.go index f5c3e1d547b..207c6381866 100644 --- a/internal/manager/task_clean.go +++ b/internal/manager/task_clean.go @@ -321,9 +321,10 @@ func (h *cleanHandler) handleRelatedScenes(ctx context.Context, fileDeleter *fil } } - if _, err := mgr.Repository.Scene.UpdatePartial(ctx, scene.ID, models.ScenePartial{ - PrimaryFileID: &newPrimaryID, - }); err != nil { + scenePartial := models.NewScenePartial() + scenePartial.PrimaryFileID = &newPrimaryID + + if _, err := mgr.Repository.Scene.UpdatePartial(ctx, scene.ID, scenePartial); err != nil { return err } } @@ -366,9 +367,10 @@ func (h *cleanHandler) handleRelatedGalleries(ctx context.Context, fileID models } } - if _, err := mgr.Repository.Gallery.UpdatePartial(ctx, g.ID, models.GalleryPartial{ - PrimaryFileID: &newPrimaryID, - }); err != nil { + galleryPartial := models.NewGalleryPartial() + galleryPartial.PrimaryFileID = &newPrimaryID + + if _, err := mgr.Repository.Gallery.UpdatePartial(ctx, g.ID, galleryPartial); err != nil { return err } } @@ -439,9 +441,10 @@ func (h *cleanHandler) handleRelatedImages(ctx context.Context, fileDeleter *fil } } - if _, err := mgr.Repository.Image.UpdatePartial(ctx, i.ID, models.ImagePartial{ - PrimaryFileID: &newPrimaryID, - }); err != nil { + imagePartial := models.NewImagePartial() + imagePartial.PrimaryFileID = &newPrimaryID + + if _, err := mgr.Repository.Image.UpdatePartial(ctx, i.ID, imagePartial); err != nil { return err } } diff --git a/internal/manager/task_generate_screenshot.go b/internal/manager/task_generate_screenshot.go index 384d8740c7b..1050ebd1c05 100644 --- a/internal/manager/task_generate_screenshot.go +++ b/internal/manager/task_generate_screenshot.go @@ -72,7 +72,7 @@ func (t *GenerateCoverTask) Start(ctx context.Context) { if err := t.txnManager.WithTxn(ctx, func(ctx context.Context) error { qb := t.txnManager.Scene - updatedScene := models.NewScenePartial() + scenePartial := models.NewScenePartial() // update the scene cover table if err := qb.UpdateCover(ctx, t.Scene.ID, coverImageData); err != nil { @@ -80,7 +80,7 @@ func (t *GenerateCoverTask) Start(ctx context.Context) { } // update the scene with the update date - _, err = qb.UpdatePartial(ctx, t.Scene.ID, updatedScene) + _, err = qb.UpdatePartial(ctx, t.Scene.ID, scenePartial) if err != nil { return fmt.Errorf("error updating scene: %v", err) } diff --git a/pkg/gallery/import.go b/pkg/gallery/import.go index 57d151245b5..9c892d3b9a9 100644 --- a/pkg/gallery/import.go +++ b/pkg/gallery/import.go @@ -117,11 +117,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 } @@ -177,7 +176,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 { @@ -235,14 +235,15 @@ func (i *Importer) populateTags(ctx context.Context) error { func (i *Importer) createTags(ctx context.Context, names []string) ([]*models.Tag, error) { var ret []*models.Tag for _, name := range names { - newTag := models.NewTag(name) + newTag := models.NewTag() + newTag.Name = name - err := i.TagWriter.Create(ctx, newTag) + err := i.TagWriter.Create(ctx, &newTag) if err != nil { return nil, err } - ret = append(ret, newTag) + ret = append(ret, &newTag) } return ret, nil diff --git a/pkg/gallery/scan.go b/pkg/gallery/scan.go index a8f52e89bb6..92ba6129afd 100644 --- a/pkg/gallery/scan.go +++ b/pkg/gallery/scan.go @@ -5,7 +5,6 @@ import ( "fmt" "path/filepath" "strings" - "time" "github.com/stashapp/stash/pkg/logger" "github.com/stashapp/stash/pkg/models" @@ -76,15 +75,11 @@ func (h *ScanHandler) Handle(ctx context.Context, f models.File, oldFile models. } // create a new gallery - now := time.Now() - newGallery := &models.Gallery{ - CreatedAt: now, - UpdatedAt: now, - } + newGallery := models.NewGallery() logger.Infof("%s doesn't exist. Creating new gallery...", f.Base().Path) - if err := h.CreatorUpdater.Create(ctx, newGallery, []models.FileID{baseFile.ID}); err != nil { + if err := h.CreatorUpdater.Create(ctx, &newGallery, []models.FileID{baseFile.ID}); err != nil { return fmt.Errorf("creating new gallery: %w", err) } @@ -92,18 +87,19 @@ func (h *ScanHandler) Handle(ctx context.Context, f models.File, oldFile models. // associate all the images in the zip file with the gallery for _, i := range images { - if _, err := h.ImageFinderUpdater.UpdatePartial(ctx, i.ID, models.ImagePartial{ + imagePartial := models.ImagePartial{ GalleryIDs: &models.UpdateIDs{ IDs: []int{newGallery.ID}, Mode: models.RelationshipUpdateModeAdd, }, - UpdatedAt: models.NewOptionalTime(now), - }); err != nil { + UpdatedAt: models.NewOptionalTime(newGallery.UpdatedAt), + } + if _, err := h.ImageFinderUpdater.UpdatePartial(ctx, i.ID, imagePartial); err != nil { return fmt.Errorf("adding image %s to gallery: %w", i.Path, err) } } - existing = []*models.Gallery{newGallery} + existing = []*models.Gallery{&newGallery} } if err := h.associateScene(ctx, existing, f); err != nil { diff --git a/pkg/gallery/update.go b/pkg/gallery/update.go index 71d92c5409b..d66da197c81 100644 --- a/pkg/gallery/update.go +++ b/pkg/gallery/update.go @@ -3,7 +3,6 @@ package gallery import ( "context" "fmt" - "time" "github.com/stashapp/stash/pkg/models" ) @@ -15,9 +14,8 @@ type ImageUpdater interface { } func (s *Service) Updated(ctx context.Context, galleryID int) error { - _, err := s.Repository.UpdatePartial(ctx, galleryID, models.GalleryPartial{ - UpdatedAt: models.NewOptionalTime(time.Now()), - }) + galleryPartial := models.NewGalleryPartial() + _, err := s.Repository.UpdatePartial(ctx, galleryID, galleryPartial) return err } @@ -55,21 +53,21 @@ func (s *Service) RemoveImages(ctx context.Context, g *models.Gallery, toRemove } func AddPerformer(ctx context.Context, qb models.GalleryUpdater, o *models.Gallery, performerID int) error { - _, err := qb.UpdatePartial(ctx, o.ID, models.GalleryPartial{ - PerformerIDs: &models.UpdateIDs{ - IDs: []int{performerID}, - Mode: models.RelationshipUpdateModeAdd, - }, - }) + galleryPartial := models.NewGalleryPartial() + galleryPartial.PerformerIDs = &models.UpdateIDs{ + IDs: []int{performerID}, + Mode: models.RelationshipUpdateModeAdd, + } + _, err := qb.UpdatePartial(ctx, o.ID, galleryPartial) return err } func AddTag(ctx context.Context, qb models.GalleryUpdater, o *models.Gallery, tagID int) error { - _, err := qb.UpdatePartial(ctx, o.ID, models.GalleryPartial{ - TagIDs: &models.UpdateIDs{ - IDs: []int{tagID}, - Mode: models.RelationshipUpdateModeAdd, - }, - }) + galleryPartial := models.NewGalleryPartial() + galleryPartial.TagIDs = &models.UpdateIDs{ + IDs: []int{tagID}, + Mode: models.RelationshipUpdateModeAdd, + } + _, err := qb.UpdatePartial(ctx, o.ID, galleryPartial) return err } diff --git a/pkg/image/import.go b/pkg/image/import.go index 4ce2287eb7b..208b535759b 100644 --- a/pkg/image/import.go +++ b/pkg/image/import.go @@ -148,11 +148,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 } @@ -261,7 +260,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 { @@ -394,14 +394,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 diff --git a/pkg/image/scan.go b/pkg/image/scan.go index d584d0f55fa..4e75e8d0c7b 100644 --- a/pkg/image/scan.go +++ b/pkg/image/scan.go @@ -6,7 +6,6 @@ import ( "fmt" "os" "path/filepath" - "time" "github.com/stashapp/stash/pkg/logger" "github.com/stashapp/stash/pkg/models" @@ -109,16 +108,12 @@ func (h *ScanHandler) Handle(ctx context.Context, f models.File, oldFile models. } } else { // create a new image - now := time.Now() - newImage := &models.Image{ - CreatedAt: now, - UpdatedAt: now, - GalleryIDs: models.NewRelatedIDs([]int{}), - } + newImage := models.NewImage() + newImage.GalleryIDs = models.NewRelatedIDs([]int{}) logger.Infof("%s doesn't exist. Creating new image...", f.Base().Path) - g, err := h.getGalleryToAssociate(ctx, newImage, f) + g, err := h.getGalleryToAssociate(ctx, &newImage, f) if err != nil { return err } @@ -129,7 +124,7 @@ func (h *ScanHandler) Handle(ctx context.Context, f models.File, oldFile models. } if err := h.CreatorUpdater.Create(ctx, &models.ImageCreateInput{ - Image: newImage, + Image: &newImage, FileIDs: []models.FileID{imageFile.ID}, }); err != nil { return fmt.Errorf("creating new image: %w", err) @@ -137,16 +132,17 @@ func (h *ScanHandler) Handle(ctx context.Context, f models.File, oldFile models. // update the gallery updated at timestamp if applicable if g != nil { - if _, err := h.GalleryFinder.UpdatePartial(ctx, g.ID, models.GalleryPartial{ - UpdatedAt: models.NewOptionalTime(time.Now()), - }); err != nil { + galleryPartial := models.GalleryPartial{ + UpdatedAt: models.NewOptionalTime(newImage.UpdatedAt), + } + if _, err := h.GalleryFinder.UpdatePartial(ctx, g.ID, galleryPartial); err != nil { return fmt.Errorf("updating gallery updated at timestamp: %w", err) } } h.PluginCache.RegisterPostHooks(ctx, newImage.ID, plugin.ImageCreatePost, nil, nil) - existing = []*models.Image{newImage} + existing = []*models.Image{&newImage} } // remove the old thumbnail if the checksum changed - we'll regenerate it @@ -215,17 +211,18 @@ func (h *ScanHandler) associateExisting(ctx context.Context, existing []*models. if changed { // always update updated_at time - if _, err := h.CreatorUpdater.UpdatePartial(ctx, i.ID, models.ImagePartial{ - GalleryIDs: galleryIDs, - UpdatedAt: models.NewOptionalTime(time.Now()), - }); err != nil { + imagePartial := models.NewImagePartial() + imagePartial.GalleryIDs = galleryIDs + + if _, err := h.CreatorUpdater.UpdatePartial(ctx, i.ID, imagePartial); err != nil { return fmt.Errorf("updating image: %w", err) } if g != nil { - if _, err := h.GalleryFinder.UpdatePartial(ctx, g.ID, models.GalleryPartial{ - UpdatedAt: models.NewOptionalTime(time.Now()), - }); err != nil { + galleryPartial := models.GalleryPartial{ + UpdatedAt: imagePartial.UpdatedAt, + } + if _, err := h.GalleryFinder.UpdatePartial(ctx, g.ID, galleryPartial); err != nil { return fmt.Errorf("updating gallery updated at timestamp: %w", err) } } @@ -252,16 +249,12 @@ func (h *ScanHandler) getOrCreateFolderBasedGallery(ctx context.Context, f model } // create a new folder-based gallery - now := time.Now() - newGallery := &models.Gallery{ - FolderID: &folderID, - CreatedAt: now, - UpdatedAt: now, - } + newGallery := models.NewGallery() + newGallery.FolderID = &folderID logger.Infof("Creating folder-based gallery for %s", filepath.Dir(f.Base().Path)) - if err := h.GalleryFinder.Create(ctx, newGallery, nil); err != nil { + if err := h.GalleryFinder.Create(ctx, &newGallery, nil); err != nil { return nil, fmt.Errorf("creating folder based gallery: %w", err) } @@ -269,11 +262,11 @@ func (h *ScanHandler) getOrCreateFolderBasedGallery(ctx context.Context, f model // it's possible that there are other images in the folder that // need to be added to the new gallery. Find and add them now. - if err := h.associateFolderImages(ctx, newGallery); err != nil { + if err := h.associateFolderImages(ctx, &newGallery); err != nil { return nil, fmt.Errorf("associating existing folder images: %w", err) } - return newGallery, nil + return &newGallery, nil } func (h *ScanHandler) associateFolderImages(ctx context.Context, g *models.Gallery) error { @@ -285,13 +278,13 @@ func (h *ScanHandler) associateFolderImages(ctx context.Context, g *models.Galle for _, ii := range i { logger.Infof("Adding %s to gallery %s", ii.Path, g.Path) - if _, err := h.CreatorUpdater.UpdatePartial(ctx, ii.ID, models.ImagePartial{ - GalleryIDs: &models.UpdateIDs{ - IDs: []int{g.ID}, - Mode: models.RelationshipUpdateModeAdd, - }, - UpdatedAt: models.NewOptionalTime(time.Now()), - }); err != nil { + imagePartial := models.NewImagePartial() + imagePartial.GalleryIDs = &models.UpdateIDs{ + IDs: []int{g.ID}, + Mode: models.RelationshipUpdateModeAdd, + } + + if _, err := h.CreatorUpdater.UpdatePartial(ctx, ii.ID, imagePartial); err != nil { return fmt.Errorf("updating image: %w", err) } } @@ -311,21 +304,17 @@ func (h *ScanHandler) getOrCreateZipBasedGallery(ctx context.Context, zipFile mo } // create a new zip-based gallery - now := time.Now() - newGallery := &models.Gallery{ - CreatedAt: now, - UpdatedAt: now, - } + newGallery := models.NewGallery() logger.Infof("%s doesn't exist. Creating new gallery...", zipFile.Base().Path) - if err := h.GalleryFinder.Create(ctx, newGallery, []models.FileID{zipFile.Base().ID}); err != nil { + if err := h.GalleryFinder.Create(ctx, &newGallery, []models.FileID{zipFile.Base().ID}); err != nil { return nil, fmt.Errorf("creating zip-based gallery: %w", err) } h.PluginCache.RegisterPostHooks(ctx, newGallery.ID, plugin.GalleryCreatePost, nil, nil) - return newGallery, nil + return &newGallery, nil } func (h *ScanHandler) getOrCreateGallery(ctx context.Context, f models.File) (*models.Gallery, error) { diff --git a/pkg/image/update.go b/pkg/image/update.go index e3a63b53d03..844e2088f71 100644 --- a/pkg/image/update.go +++ b/pkg/image/update.go @@ -7,22 +7,21 @@ import ( ) func AddPerformer(ctx context.Context, qb models.ImageUpdater, i *models.Image, performerID int) error { - _, err := qb.UpdatePartial(ctx, i.ID, models.ImagePartial{ - PerformerIDs: &models.UpdateIDs{ - IDs: []int{performerID}, - Mode: models.RelationshipUpdateModeAdd, - }, - }) - + imagePartial := models.NewImagePartial() + imagePartial.PerformerIDs = &models.UpdateIDs{ + IDs: []int{performerID}, + Mode: models.RelationshipUpdateModeAdd, + } + _, err := qb.UpdatePartial(ctx, i.ID, imagePartial) return err } func AddTag(ctx context.Context, qb models.ImageUpdater, i *models.Image, tagID int) error { - _, err := qb.UpdatePartial(ctx, i.ID, models.ImagePartial{ - TagIDs: &models.UpdateIDs{ - IDs: []int{tagID}, - Mode: models.RelationshipUpdateModeAdd, - }, - }) + imagePartial := models.NewImagePartial() + imagePartial.TagIDs = &models.UpdateIDs{ + IDs: []int{tagID}, + Mode: models.RelationshipUpdateModeAdd, + } + _, err := qb.UpdatePartial(ctx, i.ID, imagePartial) return err } diff --git a/pkg/models/model_gallery.go b/pkg/models/model_gallery.go index 8f563f06f7b..c7c74a017f3 100644 --- a/pkg/models/model_gallery.go +++ b/pkg/models/model_gallery.go @@ -36,6 +36,45 @@ type Gallery struct { PerformerIDs RelatedIDs `json:"performer_ids"` } +func NewGallery() Gallery { + currentTime := time.Now() + return Gallery{ + CreatedAt: currentTime, + UpdatedAt: currentTime, + } +} + +// GalleryPartial represents part of a Gallery object. It is used to update +// the database entry. Only non-nil fields will be updated. +type GalleryPartial struct { + // Path OptionalString + // Checksum OptionalString + // Zip OptionalBool + Title OptionalString + URL OptionalString + Date OptionalDate + Details OptionalString + // Rating expressed in 1-100 scale + Rating OptionalInt + Organized OptionalBool + StudioID OptionalInt + // FileModTime OptionalTime + CreatedAt OptionalTime + UpdatedAt OptionalTime + + SceneIDs *UpdateIDs + TagIDs *UpdateIDs + PerformerIDs *UpdateIDs + PrimaryFileID *FileID +} + +func NewGalleryPartial() GalleryPartial { + currentTime := time.Now() + return GalleryPartial{ + UpdatedAt: NewOptionalTime(currentTime), + } +} + // IsUserCreated returns true if the gallery was created by the user. // This is determined by whether the gallery has a primary file or folder. func (g *Gallery) IsUserCreated() bool { @@ -97,37 +136,6 @@ func (g Gallery) PrimaryChecksum() string { return "" } -// GalleryPartial represents part of a Gallery object. It is used to update -// the database entry. Only non-nil fields will be updated. -type GalleryPartial struct { - // Path OptionalString - // Checksum OptionalString - // Zip OptionalBool - Title OptionalString - URL OptionalString - Date OptionalDate - Details OptionalString - // Rating expressed in 1-100 scale - Rating OptionalInt - Organized OptionalBool - StudioID OptionalInt - // FileModTime OptionalTime - CreatedAt OptionalTime - UpdatedAt OptionalTime - - SceneIDs *UpdateIDs - TagIDs *UpdateIDs - PerformerIDs *UpdateIDs - PrimaryFileID *FileID -} - -func NewGalleryPartial() GalleryPartial { - updatedTime := time.Now() - return GalleryPartial{ - UpdatedAt: NewOptionalTime(updatedTime), - } -} - // GetTitle returns the title of the scene. If the Title field is empty, // then the base filename is returned. func (g Gallery) GetTitle() string { @@ -153,13 +161,3 @@ func (g Gallery) DisplayName() string { } const DefaultGthumbWidth int = 640 - -type Galleries []*Gallery - -func (g *Galleries) Append(o interface{}) { - *g = append(*g, o.(*Gallery)) -} - -func (g *Galleries) New() interface{} { - return &Gallery{} -} diff --git a/pkg/models/model_gallery_chapter.go b/pkg/models/model_gallery_chapter.go index 5c9fc05b2be..6e527106bdd 100644 --- a/pkg/models/model_gallery_chapter.go +++ b/pkg/models/model_gallery_chapter.go @@ -13,6 +13,14 @@ type GalleryChapter struct { UpdatedAt time.Time `json:"updated_at"` } +func NewGalleryChapter() GalleryChapter { + currentTime := time.Now() + return GalleryChapter{ + CreatedAt: currentTime, + UpdatedAt: currentTime, + } +} + // GalleryChapterPartial represents part of a GalleryChapter object. // It is used to update the database entry. type GalleryChapterPartial struct { @@ -24,8 +32,8 @@ type GalleryChapterPartial struct { } func NewGalleryChapterPartial() GalleryChapterPartial { - updatedTime := time.Now() + currentTime := time.Now() return GalleryChapterPartial{ - UpdatedAt: NewOptionalTime(updatedTime), + UpdatedAt: NewOptionalTime(currentTime), } } diff --git a/pkg/models/model_image.go b/pkg/models/model_image.go index 9e0a0389a77..dee7919ea21 100644 --- a/pkg/models/model_image.go +++ b/pkg/models/model_image.go @@ -36,6 +36,39 @@ type Image struct { PerformerIDs RelatedIDs `json:"performer_ids"` } +func NewImage() Image { + currentTime := time.Now() + return Image{ + CreatedAt: currentTime, + UpdatedAt: currentTime, + } +} + +type ImagePartial struct { + Title OptionalString + // Rating expressed in 1-100 scale + Rating OptionalInt + URL OptionalString + Date OptionalDate + Organized OptionalBool + OCounter OptionalInt + StudioID OptionalInt + CreatedAt OptionalTime + UpdatedAt OptionalTime + + GalleryIDs *UpdateIDs + TagIDs *UpdateIDs + PerformerIDs *UpdateIDs + PrimaryFileID *FileID +} + +func NewImagePartial() ImagePartial { + currentTime := time.Now() + return ImagePartial{ + UpdatedAt: NewOptionalTime(currentTime), + } +} + func (i *Image) LoadFiles(ctx context.Context, l FileLoader) error { return i.Files.load(func() ([]File, error) { return l.GetFiles(ctx, i.ID) @@ -107,38 +140,3 @@ type ImageCreateInput struct { *Image FileIDs []FileID } - -type ImagePartial struct { - Title OptionalString - // Rating expressed in 1-100 scale - Rating OptionalInt - URL OptionalString - Date OptionalDate - Organized OptionalBool - OCounter OptionalInt - StudioID OptionalInt - CreatedAt OptionalTime - UpdatedAt OptionalTime - - GalleryIDs *UpdateIDs - TagIDs *UpdateIDs - PerformerIDs *UpdateIDs - PrimaryFileID *FileID -} - -func NewImagePartial() ImagePartial { - updatedTime := time.Now() - return ImagePartial{ - UpdatedAt: NewOptionalTime(updatedTime), - } -} - -type Images []*Image - -func (i *Images) Append(o interface{}) { - *i = append(*i, o.(*Image)) -} - -func (i *Images) New() interface{} { - return &Image{} -} diff --git a/pkg/models/model_movie.go b/pkg/models/model_movie.go index cf7f997d887..152f0d3bbb5 100644 --- a/pkg/models/model_movie.go +++ b/pkg/models/model_movie.go @@ -20,6 +20,14 @@ type Movie struct { UpdatedAt time.Time `json:"updated_at"` } +func NewMovie() Movie { + currentTime := time.Now() + return Movie{ + CreatedAt: currentTime, + UpdatedAt: currentTime, + } +} + type MoviePartial struct { Name OptionalString Aliases OptionalString @@ -35,30 +43,11 @@ type MoviePartial struct { UpdatedAt OptionalTime } -var DefaultMovieImage = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4wgVBQsJl1CMZAAAASJJREFUeNrt3N0JwyAYhlEj3cj9R3Cm5rbkqtAP+qrnGaCYHPwJpLlaa++mmLpbAERAgAgIEAEBIiBABERAgAgIEAEBIiBABERAgAgIEAHZuVflj40x4i94zhk9vqsVvEq6AsQqMP1EjORx20OACAgQRRx7T+zzcFBxcjNDfoB4ntQqTm5Awo7MlqywZxcgYQ+RlqywJ3ozJAQCSBiEJSsQA0gYBpDAgAARECACAkRAgAgIEAERECACAmSjUv6eAOSB8m8YIGGzBUjYbAESBgMkbBkDEjZbgITBAClcxiqQvEoatreYIWEBASIgJ4Gkf11ntXH3nS9uxfGWfJ5J9hAgAgJEQAQEiIAAERAgAgJEQAQEiIAAERAgAgJEQAQEiL7qBuc6RKLHxr0CAAAAAElFTkSuQmCC" - -func NewMovie(name string) *Movie { - currentTime := time.Now() - return &Movie{ - Name: name, - CreatedAt: currentTime, - UpdatedAt: currentTime, - } -} - func NewMoviePartial() MoviePartial { - updatedTime := time.Now() + currentTime := time.Now() return MoviePartial{ - UpdatedAt: NewOptionalTime(updatedTime), + UpdatedAt: NewOptionalTime(currentTime), } } -type Movies []*Movie - -func (m *Movies) Append(o interface{}) { - *m = append(*m, o.(*Movie)) -} - -func (m *Movies) New() interface{} { - return &Movie{} -} +var DefaultMovieImage = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4wgVBQsJl1CMZAAAASJJREFUeNrt3N0JwyAYhlEj3cj9R3Cm5rbkqtAP+qrnGaCYHPwJpLlaa++mmLpbAERAgAgIEAEBIiBABERAgAgIEAEBIiBABERAgAgIEAHZuVflj40x4i94zhk9vqsVvEq6AsQqMP1EjORx20OACAgQRRx7T+zzcFBxcjNDfoB4ntQqTm5Awo7MlqywZxcgYQ+RlqywJ3ozJAQCSBiEJSsQA0gYBpDAgAARECACAkRAgAgIEAERECACAmSjUv6eAOSB8m8YIGGzBUjYbAESBgMkbBkDEjZbgITBAClcxiqQvEoatreYIWEBASIgJ4Gkf11ntXH3nS9uxfGWfJ5J9hAgAgJEQAQEiIAAERAgAgJEQAQEiIAAERAgAgJEQAQEiL7qBuc6RKLHxr0CAAAAAElFTkSuQmCC" diff --git a/pkg/models/model_performer.go b/pkg/models/model_performer.go index a620f306516..09f92e13c6d 100644 --- a/pkg/models/model_performer.go +++ b/pkg/models/model_performer.go @@ -41,38 +41,12 @@ type Performer struct { StashIDs RelatedStashIDs `json:"stash_ids"` } -func (s *Performer) LoadAliases(ctx context.Context, l AliasLoader) error { - return s.Aliases.load(func() ([]string, error) { - return l.GetAliases(ctx, s.ID) - }) -} - -func (s *Performer) LoadTagIDs(ctx context.Context, l TagIDLoader) error { - return s.TagIDs.load(func() ([]int, error) { - return l.GetTagIDs(ctx, s.ID) - }) -} - -func (s *Performer) LoadStashIDs(ctx context.Context, l StashIDLoader) error { - return s.StashIDs.load(func() ([]StashID, error) { - return l.GetStashIDs(ctx, s.ID) - }) -} - -func (s *Performer) LoadRelationships(ctx context.Context, l PerformerReader) error { - if err := s.LoadAliases(ctx, l); err != nil { - return err - } - - if err := s.LoadTagIDs(ctx, l); err != nil { - return err - } - - if err := s.LoadStashIDs(ctx, l); err != nil { - return err +func NewPerformer() Performer { + currentTime := time.Now() + return Performer{ + CreatedAt: currentTime, + UpdatedAt: currentTime, } - - return nil } // PerformerPartial represents part of a Performer object. It is used to update @@ -112,28 +86,43 @@ type PerformerPartial struct { StashIDs *UpdateStashIDs } -func NewPerformer(name string) *Performer { +func NewPerformerPartial() PerformerPartial { currentTime := time.Now() - return &Performer{ - Name: name, - CreatedAt: currentTime, - UpdatedAt: currentTime, + return PerformerPartial{ + UpdatedAt: NewOptionalTime(currentTime), } } -func NewPerformerPartial() PerformerPartial { - updatedTime := time.Now() - return PerformerPartial{ - UpdatedAt: NewOptionalTime(updatedTime), - } +func (s *Performer) LoadAliases(ctx context.Context, l AliasLoader) error { + return s.Aliases.load(func() ([]string, error) { + return l.GetAliases(ctx, s.ID) + }) } -type Performers []*Performer +func (s *Performer) LoadTagIDs(ctx context.Context, l TagIDLoader) error { + return s.TagIDs.load(func() ([]int, error) { + return l.GetTagIDs(ctx, s.ID) + }) +} -func (p *Performers) Append(o interface{}) { - *p = append(*p, o.(*Performer)) +func (s *Performer) LoadStashIDs(ctx context.Context, l StashIDLoader) error { + return s.StashIDs.load(func() ([]StashID, error) { + return l.GetStashIDs(ctx, s.ID) + }) } -func (p *Performers) New() interface{} { - return &Performer{} +func (s *Performer) LoadRelationships(ctx context.Context, l PerformerReader) error { + if err := s.LoadAliases(ctx, l); err != nil { + return err + } + + if err := s.LoadTagIDs(ctx, l); err != nil { + return err + } + + if err := s.LoadStashIDs(ctx, l); err != nil { + return err + } + + return nil } diff --git a/pkg/models/model_saved_filter.go b/pkg/models/model_saved_filter.go index 51c50be51d1..d680e7c95ef 100644 --- a/pkg/models/model_saved_filter.go +++ b/pkg/models/model_saved_filter.go @@ -67,13 +67,3 @@ type SavedFilter struct { ObjectFilter map[string]interface{} `json:"object_filter"` UIOptions map[string]interface{} `json:"ui_options"` } - -type SavedFilters []*SavedFilter - -func (m *SavedFilters) Append(o interface{}) { - *m = append(*m, o.(*SavedFilter)) -} - -func (m *SavedFilters) New() interface{} { - return &SavedFilter{} -} diff --git a/pkg/models/model_scene.go b/pkg/models/model_scene.go index dca923d4bb7..4cd434eed80 100644 --- a/pkg/models/model_scene.go +++ b/pkg/models/model_scene.go @@ -48,6 +48,50 @@ type Scene struct { StashIDs RelatedStashIDs `json:"stash_ids"` } +func NewScene() Scene { + currentTime := time.Now() + return Scene{ + CreatedAt: currentTime, + UpdatedAt: currentTime, + } +} + +// ScenePartial represents part of a Scene object. It is used to update +// the database entry. +type ScenePartial struct { + Title OptionalString + Code OptionalString + Details OptionalString + Director OptionalString + Date OptionalDate + // Rating expressed in 1-100 scale + Rating OptionalInt + Organized OptionalBool + OCounter OptionalInt + StudioID OptionalInt + CreatedAt OptionalTime + UpdatedAt OptionalTime + ResumeTime OptionalFloat64 + PlayDuration OptionalFloat64 + PlayCount OptionalInt + LastPlayedAt OptionalTime + + URLs *UpdateStrings + GalleryIDs *UpdateIDs + TagIDs *UpdateIDs + PerformerIDs *UpdateIDs + MovieIDs *UpdateMovieIDs + StashIDs *UpdateStashIDs + PrimaryFileID *FileID +} + +func NewScenePartial() ScenePartial { + currentTime := time.Now() + return ScenePartial{ + UpdatedAt: NewOptionalTime(currentTime), + } +} + func (s *Scene) LoadURLs(ctx context.Context, l URLLoader) error { return s.URLs.load(func() ([]string, error) { return l.GetURLs(ctx, s.ID) @@ -145,42 +189,6 @@ func (s *Scene) LoadRelationships(ctx context.Context, l SceneReader) error { return nil } -// ScenePartial represents part of a Scene object. It is used to update -// the database entry. -type ScenePartial struct { - Title OptionalString - Code OptionalString - Details OptionalString - Director OptionalString - Date OptionalDate - // Rating expressed in 1-100 scale - Rating OptionalInt - Organized OptionalBool - OCounter OptionalInt - StudioID OptionalInt - CreatedAt OptionalTime - UpdatedAt OptionalTime - ResumeTime OptionalFloat64 - PlayDuration OptionalFloat64 - PlayCount OptionalInt - LastPlayedAt OptionalTime - - URLs *UpdateStrings - GalleryIDs *UpdateIDs - TagIDs *UpdateIDs - PerformerIDs *UpdateIDs - MovieIDs *UpdateMovieIDs - StashIDs *UpdateStashIDs - PrimaryFileID *FileID -} - -func NewScenePartial() ScenePartial { - updatedTime := time.Now() - return ScenePartial{ - UpdatedAt: NewOptionalTime(updatedTime), - } -} - // UpdateInput constructs a SceneUpdateInput using the populated fields in the ScenePartial object. func (s ScenePartial) UpdateInput(id int) SceneUpdateInput { var dateStr *string @@ -267,16 +275,6 @@ type SceneFileType struct { Bitrate *int `graphql:"bitrate" json:"bitrate"` } -type Scenes []*Scene - -func (s *Scenes) Append(o interface{}) { - *s = append(*s, o.(*Scene)) -} - -func (s *Scenes) New() interface{} { - return &Scene{} -} - type VideoCaption struct { LanguageCode string `json:"language_code"` Filename string `json:"filename"` diff --git a/pkg/models/model_scene_marker.go b/pkg/models/model_scene_marker.go index 1e9ac611589..df77afecd77 100644 --- a/pkg/models/model_scene_marker.go +++ b/pkg/models/model_scene_marker.go @@ -14,6 +14,14 @@ type SceneMarker struct { UpdatedAt time.Time `json:"updated_at"` } +func NewSceneMarker() SceneMarker { + currentTime := time.Now() + return SceneMarker{ + CreatedAt: currentTime, + UpdatedAt: currentTime, + } +} + // SceneMarkerPartial represents part of a SceneMarker object. // It is used to update the database entry. type SceneMarkerPartial struct { @@ -26,8 +34,8 @@ type SceneMarkerPartial struct { } func NewSceneMarkerPartial() SceneMarkerPartial { - updatedTime := time.Now() + currentTime := time.Now() return SceneMarkerPartial{ - UpdatedAt: NewOptionalTime(updatedTime), + UpdatedAt: NewOptionalTime(currentTime), } } diff --git a/pkg/models/model_scraped_item.go b/pkg/models/model_scraped_item.go index 97d403b10ef..cb383c082e7 100644 --- a/pkg/models/model_scraped_item.go +++ b/pkg/models/model_scraped_item.go @@ -3,7 +3,6 @@ package models import ( "context" "strconv" - "time" "github.com/stashapp/stash/pkg/sliceutil/stringslice" "github.com/stashapp/stash/pkg/utils" @@ -23,17 +22,12 @@ type ScrapedStudio struct { func (ScrapedStudio) IsScrapedContent() {} func (s *ScrapedStudio) ToStudio(endpoint string, excluded map[string]bool) *Studio { - now := time.Now() - // Populate a new studio from the input - newStudio := Studio{ - Name: s.Name, - CreatedAt: now, - UpdatedAt: now, - } + ret := NewStudio() + ret.Name = s.Name if s.RemoteSiteID != nil && endpoint != "" { - newStudio.StashIDs = NewRelatedStashIDs([]StashID{ + ret.StashIDs = NewRelatedStashIDs([]StashID{ { Endpoint: endpoint, StashID: *s.RemoteSiteID, @@ -42,15 +36,15 @@ func (s *ScrapedStudio) ToStudio(endpoint string, excluded map[string]bool) *Stu } if s.URL != nil && !excluded["url"] { - newStudio.URL = *s.URL + ret.URL = *s.URL } if s.Parent != nil && s.Parent.StoredID != nil && !excluded["parent"] && !excluded["parent_studio"] { parentId, _ := strconv.Atoi(*s.Parent.StoredID) - newStudio.ParentID = &parentId + ret.ParentID = &parentId } - return &newStudio + return &ret } func (s *ScrapedStudio) GetImage(ctx context.Context, excluded map[string]bool) ([]byte, error) { @@ -69,17 +63,15 @@ func (s *ScrapedStudio) GetImage(ctx context.Context, excluded map[string]bool) } func (s *ScrapedStudio) ToPartial(id *string, endpoint string, excluded map[string]bool, existingStashIDs []StashID) *StudioPartial { - partial := StudioPartial{ - UpdatedAt: NewOptionalTime(time.Now()), - } - partial.ID, _ = strconv.Atoi(*id) + ret := NewStudioPartial() + ret.ID, _ = strconv.Atoi(*id) if s.Name != "" && !excluded["name"] { - partial.Name = NewOptionalString(s.Name) + ret.Name = NewOptionalString(s.Name) } if s.URL != nil && !excluded["url"] { - partial.URL = NewOptionalString(*s.URL) + ret.URL = NewOptionalString(*s.URL) } if s.Parent != nil && !excluded["parent"] { @@ -87,25 +79,25 @@ func (s *ScrapedStudio) ToPartial(id *string, endpoint string, excluded map[stri parentID, _ := strconv.Atoi(*s.Parent.StoredID) if parentID > 0 { // This is to be set directly as we know it has a value and the translator won't have the field - partial.ParentID = NewOptionalInt(parentID) + ret.ParentID = NewOptionalInt(parentID) } } } else { - partial.ParentID = NewOptionalIntPtr(nil) + ret.ParentID = NewOptionalIntPtr(nil) } if s.RemoteSiteID != nil && endpoint != "" { - partial.StashIDs = &UpdateStashIDs{ + ret.StashIDs = &UpdateStashIDs{ StashIDs: existingStashIDs, Mode: RelationshipUpdateModeSet, } - partial.StashIDs.Set(StashID{ + ret.StashIDs.Set(StashID{ Endpoint: endpoint, StashID: *s.RemoteSiteID, }) } - return &partial + return &ret } // A performer from a scraping operation... @@ -145,7 +137,8 @@ type ScrapedPerformer struct { func (ScrapedPerformer) IsScrapedContent() {} func (p *ScrapedPerformer) ToPerformer(endpoint string, excluded map[string]bool) *Performer { - ret := NewPerformer(*p.Name) + ret := NewPerformer() + ret.Name = *p.Name if p.Aliases != nil && !excluded["aliases"] { ret.Aliases = NewRelatedStrings(stringslice.FromString(*p.Aliases, ",")) @@ -244,7 +237,7 @@ func (p *ScrapedPerformer) ToPerformer(endpoint string, excluded map[string]bool }) } - return ret + return &ret } func (p *ScrapedPerformer) GetImage(ctx context.Context, excluded map[string]bool) ([]byte, error) { @@ -263,10 +256,10 @@ func (p *ScrapedPerformer) GetImage(ctx context.Context, excluded map[string]boo } func (p *ScrapedPerformer) ToPartial(endpoint string, excluded map[string]bool, existingStashIDs []StashID) PerformerPartial { - partial := NewPerformerPartial() + ret := NewPerformerPartial() if p.Aliases != nil && !excluded["aliases"] { - partial.Aliases = &UpdateStrings{ + ret.Aliases = &UpdateStrings{ Values: stringslice.FromString(*p.Aliases, ","), Mode: RelationshipUpdateModeSet, } @@ -274,88 +267,88 @@ func (p *ScrapedPerformer) ToPartial(endpoint string, excluded map[string]bool, if p.Birthdate != nil && !excluded["birthdate"] { date, err := ParseDate(*p.Birthdate) if err == nil { - partial.Birthdate = NewOptionalDate(date) + ret.Birthdate = NewOptionalDate(date) } } if p.DeathDate != nil && !excluded["death_date"] { date, err := ParseDate(*p.DeathDate) if err == nil { - partial.DeathDate = NewOptionalDate(date) + ret.DeathDate = NewOptionalDate(date) } } if p.CareerLength != nil && !excluded["career_length"] { - partial.CareerLength = NewOptionalString(*p.CareerLength) + ret.CareerLength = NewOptionalString(*p.CareerLength) } if p.Country != nil && !excluded["country"] { - partial.Country = NewOptionalString(*p.Country) + ret.Country = NewOptionalString(*p.Country) } if p.Ethnicity != nil && !excluded["ethnicity"] { - partial.Ethnicity = NewOptionalString(*p.Ethnicity) + ret.Ethnicity = NewOptionalString(*p.Ethnicity) } if p.EyeColor != nil && !excluded["eye_color"] { - partial.EyeColor = NewOptionalString(*p.EyeColor) + ret.EyeColor = NewOptionalString(*p.EyeColor) } if p.HairColor != nil && !excluded["hair_color"] { - partial.HairColor = NewOptionalString(*p.HairColor) + ret.HairColor = NewOptionalString(*p.HairColor) } if p.FakeTits != nil && !excluded["fake_tits"] { - partial.FakeTits = NewOptionalString(*p.FakeTits) + ret.FakeTits = NewOptionalString(*p.FakeTits) } if p.Gender != nil && !excluded["gender"] { - partial.Gender = NewOptionalString(*p.Gender) + ret.Gender = NewOptionalString(*p.Gender) } if p.Height != nil && !excluded["height"] { h, err := strconv.Atoi(*p.Height) if err == nil { - partial.Height = NewOptionalInt(h) + ret.Height = NewOptionalInt(h) } } if p.Weight != nil && !excluded["weight"] { w, err := strconv.Atoi(*p.Weight) if err == nil { - partial.Weight = NewOptionalInt(w) + ret.Weight = NewOptionalInt(w) } } if p.Instagram != nil && !excluded["instagram"] { - partial.Instagram = NewOptionalString(*p.Instagram) + ret.Instagram = NewOptionalString(*p.Instagram) } if p.Measurements != nil && !excluded["measurements"] { - partial.Measurements = NewOptionalString(*p.Measurements) + ret.Measurements = NewOptionalString(*p.Measurements) } if p.Name != nil && !excluded["name"] { - partial.Name = NewOptionalString(*p.Name) + ret.Name = NewOptionalString(*p.Name) } if p.Disambiguation != nil && !excluded["disambiguation"] { - partial.Disambiguation = NewOptionalString(*p.Disambiguation) + ret.Disambiguation = NewOptionalString(*p.Disambiguation) } if p.Details != nil && !excluded["details"] { - partial.Details = NewOptionalString(*p.Details) + ret.Details = NewOptionalString(*p.Details) } if p.Piercings != nil && !excluded["piercings"] { - partial.Piercings = NewOptionalString(*p.Piercings) + ret.Piercings = NewOptionalString(*p.Piercings) } if p.Tattoos != nil && !excluded["tattoos"] { - partial.Tattoos = NewOptionalString(*p.Tattoos) + ret.Tattoos = NewOptionalString(*p.Tattoos) } if p.Twitter != nil && !excluded["twitter"] { - partial.Twitter = NewOptionalString(*p.Twitter) + ret.Twitter = NewOptionalString(*p.Twitter) } if p.URL != nil && !excluded["url"] { - partial.URL = NewOptionalString(*p.URL) + ret.URL = NewOptionalString(*p.URL) } if p.RemoteSiteID != nil && endpoint != "" { - partial.StashIDs = &UpdateStashIDs{ + ret.StashIDs = &UpdateStashIDs{ StashIDs: existingStashIDs, Mode: RelationshipUpdateModeSet, } - partial.StashIDs.Set(StashID{ + ret.StashIDs.Set(StashID{ Endpoint: endpoint, StashID: *p.RemoteSiteID, }) } - return partial + return ret } type ScrapedTag struct { diff --git a/pkg/models/model_studio.go b/pkg/models/model_studio.go index 9f1deca4974..109535be1b5 100644 --- a/pkg/models/model_studio.go +++ b/pkg/models/model_studio.go @@ -21,28 +21,12 @@ type Studio struct { StashIDs RelatedStashIDs `json:"stash_ids"` } -func (s *Studio) LoadAliases(ctx context.Context, l AliasLoader) error { - return s.Aliases.load(func() ([]string, error) { - return l.GetAliases(ctx, s.ID) - }) -} - -func (s *Studio) LoadStashIDs(ctx context.Context, l StashIDLoader) error { - return s.StashIDs.load(func() ([]StashID, error) { - return l.GetStashIDs(ctx, s.ID) - }) -} - -func (s *Studio) LoadRelationships(ctx context.Context, l PerformerReader) error { - if err := s.LoadAliases(ctx, l); err != nil { - return err +func NewStudio() Studio { + currentTime := time.Now() + return Studio{ + CreatedAt: currentTime, + UpdatedAt: currentTime, } - - if err := s.LoadStashIDs(ctx, l); err != nil { - return err - } - - return nil } // StudioPartial represents part of a Studio object. It is used to update the database entry. @@ -62,12 +46,33 @@ type StudioPartial struct { StashIDs *UpdateStashIDs } -type Studios []*Studio +func NewStudioPartial() StudioPartial { + currentTime := time.Now() + return StudioPartial{ + UpdatedAt: NewOptionalTime(currentTime), + } +} -func (s *Studios) Append(o interface{}) { - *s = append(*s, o.(*Studio)) +func (s *Studio) LoadAliases(ctx context.Context, l AliasLoader) error { + return s.Aliases.load(func() ([]string, error) { + return l.GetAliases(ctx, s.ID) + }) +} + +func (s *Studio) LoadStashIDs(ctx context.Context, l StashIDLoader) error { + return s.StashIDs.load(func() ([]StashID, error) { + return l.GetStashIDs(ctx, s.ID) + }) } -func (s *Studios) New() interface{} { - return &Studio{} +func (s *Studio) LoadRelationships(ctx context.Context, l PerformerReader) error { + if err := s.LoadAliases(ctx, l); err != nil { + return err + } + + if err := s.LoadStashIDs(ctx, l); err != nil { + return err + } + + return nil } diff --git a/pkg/models/model_tag.go b/pkg/models/model_tag.go index e07eee77287..f8c49c5321f 100644 --- a/pkg/models/model_tag.go +++ b/pkg/models/model_tag.go @@ -13,6 +13,14 @@ type Tag struct { UpdatedAt time.Time `json:"updated_at"` } +func NewTag() Tag { + currentTime := time.Now() + return Tag{ + CreatedAt: currentTime, + UpdatedAt: currentTime, + } +} + type TagPartial struct { Name OptionalString Description OptionalString @@ -21,43 +29,14 @@ type TagPartial struct { UpdatedAt OptionalTime } -type TagPath struct { - Tag - Path string `json:"path"` -} - -func NewTag(name string) *Tag { - currentTime := time.Now() - return &Tag{ - Name: name, - CreatedAt: currentTime, - UpdatedAt: currentTime, - } -} - func NewTagPartial() TagPartial { - updatedTime := time.Now() + currentTime := time.Now() return TagPartial{ - UpdatedAt: NewOptionalTime(updatedTime), + UpdatedAt: NewOptionalTime(currentTime), } } -type Tags []*Tag - -func (t *Tags) Append(o interface{}) { - *t = append(*t, o.(*Tag)) -} - -func (t *Tags) New() interface{} { - return &Tag{} -} - -type TagPaths []*TagPath - -func (t *TagPaths) Append(o interface{}) { - *t = append(*t, o.(*TagPath)) -} - -func (t *TagPaths) New() interface{} { - return &TagPath{} +type TagPath struct { + Tag + Path string `json:"path"` } diff --git a/pkg/movie/import.go b/pkg/movie/import.go index e231031e865..8004798ae53 100644 --- a/pkg/movie/import.go +++ b/pkg/movie/import.go @@ -109,11 +109,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 } diff --git a/pkg/performer/import.go b/pkg/performer/import.go index 1c3c075a447..9f57d97fe9a 100644 --- a/pkg/performer/import.go +++ b/pkg/performer/import.go @@ -101,14 +101,15 @@ func importTags(ctx context.Context, tagWriter models.TagFinderCreator, names [] func createTags(ctx context.Context, tagWriter models.TagFinderCreator, 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 diff --git a/pkg/scene/import.go b/pkg/scene/import.go index e2cfe8abaff..8c67cecdf39 100644 --- a/pkg/scene/import.go +++ b/pkg/scene/import.go @@ -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 diff --git a/pkg/scene/scan.go b/pkg/scene/scan.go index f16d0d5c61b..821485eb9a6 100644 --- a/pkg/scene/scan.go +++ b/pkg/scene/scan.go @@ -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) } } diff --git a/pkg/scene/update.go b/pkg/scene/update.go index f0a1a030f83..629fdedad47 100644 --- a/pkg/scene/update.go +++ b/pkg/scene/update.go @@ -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 } diff --git a/pkg/sqlite/tag.go b/pkg/sqlite/tag.go index ce09da4464f..33273525402 100644 --- a/pkg/sqlite/tag.go +++ b/pkg/sqlite/tag.go @@ -890,9 +890,9 @@ func (qb *TagStore) queryTags(ctx context.Context, query string, args []interfac return ret, nil } -func (qb *TagStore) queryTagPaths(ctx context.Context, query string, args []interface{}) (models.TagPaths, error) { +func (qb *TagStore) queryTagPaths(ctx context.Context, query string, args []interface{}) ([]*models.TagPath, error) { const single = false - var ret models.TagPaths + var ret []*models.TagPath if err := qb.queryFunc(ctx, query, args, single, func(r *sqlx.Rows) error { var f tagPathRow if err := r.StructScan(&f); err != nil { diff --git a/pkg/studio/import.go b/pkg/studio/import.go index df712daab79..1af5ec5c3e0 100644 --- a/pkg/studio/import.go +++ b/pkg/studio/import.go @@ -77,11 +77,10 @@ func (i *Importer) populateParentStudio(ctx context.Context) error { } func (i *Importer) createParentStudio(ctx context.Context, name string) (int, error) { - newStudio := &models.Studio{ - Name: name, - } + newStudio := models.NewStudio() + newStudio.Name = name - err := i.ReaderWriter.Create(ctx, newStudio) + err := i.ReaderWriter.Create(ctx, &newStudio) if err != nil { return 0, err } diff --git a/pkg/tag/import.go b/pkg/tag/import.go index 368815bbe44..6905d15ad73 100644 --- a/pkg/tag/import.go +++ b/pkg/tag/import.go @@ -151,9 +151,10 @@ func (i *Importer) getParents(ctx context.Context) ([]int, error) { } func (i *Importer) createParent(ctx context.Context, name string) (int, error) { - newTag := models.NewTag(name) + newTag := models.NewTag() + newTag.Name = name - err := i.ReaderWriter.Create(ctx, newTag) + err := i.ReaderWriter.Create(ctx, &newTag) if err != nil { return 0, err }