Data layer restructuring (#997)

* Move query builders to sqlite package
* Add transaction system
* Wrap model resolvers in transaction
* Add error return value for StringSliceToIntSlice
* Update/refactor mutation resolvers
* Convert query builders
* Remove unused join types
* Add stash id unit tests
* Use WAL journal mode
This commit is contained in:
WithoutPants
2021-01-18 12:23:20 +11:00
committed by GitHub
parent 7bae990c67
commit 1e04deb3d4
168 changed files with 12683 additions and 10863 deletions

View File

@@ -6,11 +6,14 @@ import (
"strconv"
"github.com/go-chi/chi"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/utils"
)
type studioRoutes struct{}
type studioRoutes struct {
txnManager models.TransactionManager
}
func (rs studioRoutes) Routes() chi.Router {
r := chi.NewRouter()
@@ -25,12 +28,14 @@ func (rs studioRoutes) Routes() chi.Router {
func (rs studioRoutes) Image(w http.ResponseWriter, r *http.Request) {
studio := r.Context().Value(studioKey).(*models.Studio)
qb := models.NewStudioQueryBuilder()
var image []byte
defaultParam := r.URL.Query().Get("default")
var image []byte
if defaultParam != "true" {
image, _ = qb.GetStudioImage(studio.ID, nil)
rs.txnManager.WithReadTxn(r.Context(), func(repo models.ReaderRepository) error {
image, _ = repo.Studio().GetImage(studio.ID)
return nil
})
}
if len(image) == 0 {
@@ -48,9 +53,12 @@ func StudioCtx(next http.Handler) http.Handler {
return
}
qb := models.NewStudioQueryBuilder()
studio, err := qb.Find(studioID, nil)
if err != nil {
var studio *models.Studio
if err := manager.GetInstance().TxnManager.WithReadTxn(r.Context(), func(repo models.ReaderRepository) error {
var err error
studio, err = repo.Studio().Find(studioID)
return err
}); err != nil {
http.Error(w, http.StatusText(404), 404)
return
}