Restructure data layer (#2532)

* Add new txn manager interface
* Add txn management to sqlite
* Rename get to getByID
* Add contexts to repository methods
* Update query builders
* Add context to reader writer interfaces
* Use repository in resolver
* Tighten interfaces
* Tighten interfaces in dlna
* Tighten interfaces in match package
* Tighten interfaces in scraper package
* Tighten interfaces in scan code
* Tighten interfaces on autotag package
* Remove ReaderWriter usage
* Merge database package into sqlite
This commit is contained in:
WithoutPants
2022-05-19 17:49:32 +10:00
parent 7b5bd80515
commit 964b559309
244 changed files with 7377 additions and 6699 deletions

View File

@@ -1,6 +1,7 @@
package studio
import (
"context"
"fmt"
"github.com/stashapp/stash/pkg/models"
@@ -9,8 +10,15 @@ import (
"github.com/stashapp/stash/pkg/utils"
)
type FinderImageStashIDGetter interface {
Finder
GetAliases(ctx context.Context, studioID int) ([]string, error)
GetImage(ctx context.Context, studioID int) ([]byte, error)
GetStashIDs(ctx context.Context, studioID int) ([]*models.StashID, error)
}
// ToJSON converts a Studio object into its JSON equivalent.
func ToJSON(reader models.StudioReader, studio *models.Studio) (*jsonschema.Studio, error) {
func ToJSON(ctx context.Context, reader FinderImageStashIDGetter, studio *models.Studio) (*jsonschema.Studio, error) {
newStudioJSON := jsonschema.Studio{
IgnoreAutoTag: studio.IgnoreAutoTag,
CreatedAt: json.JSONTime{Time: studio.CreatedAt.Timestamp},
@@ -30,7 +38,7 @@ func ToJSON(reader models.StudioReader, studio *models.Studio) (*jsonschema.Stud
}
if studio.ParentID.Valid {
parent, err := reader.Find(int(studio.ParentID.Int64))
parent, err := reader.Find(ctx, int(studio.ParentID.Int64))
if err != nil {
return nil, fmt.Errorf("error getting parent studio: %v", err)
}
@@ -44,14 +52,14 @@ func ToJSON(reader models.StudioReader, studio *models.Studio) (*jsonschema.Stud
newStudioJSON.Rating = int(studio.Rating.Int64)
}
aliases, err := reader.GetAliases(studio.ID)
aliases, err := reader.GetAliases(ctx, studio.ID)
if err != nil {
return nil, fmt.Errorf("error getting studio aliases: %v", err)
}
newStudioJSON.Aliases = aliases
image, err := reader.GetImage(studio.ID)
image, err := reader.GetImage(ctx, studio.ID)
if err != nil {
return nil, fmt.Errorf("error getting studio image: %v", err)
}
@@ -60,7 +68,7 @@ func ToJSON(reader models.StudioReader, studio *models.Studio) (*jsonschema.Stud
newStudioJSON.Image = utils.GetBase64StringFromData(image)
}
stashIDs, _ := reader.GetStashIDs(studio.ID)
stashIDs, _ := reader.GetStashIDs(ctx, studio.ID)
var ret []models.StashID
for _, stashID := range stashIDs {
newJoin := models.StashID{