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

@@ -12,7 +12,9 @@ import (
"github.com/stashapp/stash/pkg/utils"
)
type imageRoutes struct{}
type imageRoutes struct {
txnManager models.TransactionManager
}
func (rs imageRoutes) Routes() chi.Router {
r := chi.NewRouter()
@@ -57,12 +59,16 @@ func ImageCtx(next http.Handler) http.Handler {
imageID, _ := strconv.Atoi(imageIdentifierQueryParam)
var image *models.Image
qb := models.NewImageQueryBuilder()
if imageID == 0 {
image, _ = qb.FindByChecksum(imageIdentifierQueryParam)
} else {
image, _ = qb.Find(imageID)
}
manager.GetInstance().TxnManager.WithReadTxn(r.Context(), func(repo models.ReaderRepository) error {
qb := repo.Image()
if imageID == 0 {
image, _ = qb.FindByChecksum(imageIdentifierQueryParam)
} else {
image, _ = qb.Find(imageID)
}
return nil
})
if image == nil {
http.Error(w, http.StatusText(404), 404)