mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
[Files Refactor] Performance tuning (#2819)
* Load scene relationships on demand * Load image relationships on demand * Load gallery relationships on demand * Add dataloaden * Use dataloaders * Use where in for other find many functions
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/sliceutil/intslice"
|
||||
"github.com/stashapp/stash/pkg/utils"
|
||||
)
|
||||
|
||||
@@ -87,53 +86,32 @@ func (u UpdateSet) UpdateInput() models.SceneUpdateInput {
|
||||
return ret
|
||||
}
|
||||
|
||||
func AddPerformer(ctx context.Context, qb PartialUpdater, o *models.Scene, performerID int) (bool, error) {
|
||||
if !intslice.IntInclude(o.PerformerIDs, performerID) {
|
||||
if _, err := qb.UpdatePartial(ctx, o.ID, models.ScenePartial{
|
||||
PerformerIDs: &models.UpdateIDs{
|
||||
IDs: []int{performerID},
|
||||
Mode: models.RelationshipUpdateModeAdd,
|
||||
},
|
||||
}); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
func AddPerformer(ctx context.Context, qb PartialUpdater, o *models.Scene, performerID int) error {
|
||||
_, err := qb.UpdatePartial(ctx, o.ID, models.ScenePartial{
|
||||
PerformerIDs: &models.UpdateIDs{
|
||||
IDs: []int{performerID},
|
||||
Mode: models.RelationshipUpdateModeAdd,
|
||||
},
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func AddTag(ctx context.Context, qb PartialUpdater, o *models.Scene, tagID int) (bool, error) {
|
||||
if !intslice.IntInclude(o.TagIDs, tagID) {
|
||||
if _, err := qb.UpdatePartial(ctx, o.ID, models.ScenePartial{
|
||||
TagIDs: &models.UpdateIDs{
|
||||
IDs: []int{tagID},
|
||||
Mode: models.RelationshipUpdateModeAdd,
|
||||
},
|
||||
}); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
func AddTag(ctx context.Context, qb PartialUpdater, o *models.Scene, tagID int) error {
|
||||
_, err := qb.UpdatePartial(ctx, o.ID, models.ScenePartial{
|
||||
TagIDs: &models.UpdateIDs{
|
||||
IDs: []int{tagID},
|
||||
Mode: models.RelationshipUpdateModeAdd,
|
||||
},
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func AddGallery(ctx context.Context, qb PartialUpdater, o *models.Scene, galleryID int) (bool, error) {
|
||||
if !intslice.IntInclude(o.GalleryIDs, galleryID) {
|
||||
if _, err := qb.UpdatePartial(ctx, o.ID, models.ScenePartial{
|
||||
TagIDs: &models.UpdateIDs{
|
||||
IDs: []int{galleryID},
|
||||
Mode: models.RelationshipUpdateModeAdd,
|
||||
},
|
||||
}); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
func AddGallery(ctx context.Context, qb PartialUpdater, o *models.Scene, galleryID int) error {
|
||||
_, err := qb.UpdatePartial(ctx, o.ID, models.ScenePartial{
|
||||
TagIDs: &models.UpdateIDs{
|
||||
IDs: []int{galleryID},
|
||||
Mode: models.RelationshipUpdateModeAdd,
|
||||
},
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user