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:
@@ -1,6 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
@@ -35,9 +36,27 @@ type Gallery struct {
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
SceneIDs []int `json:"scene_ids"`
|
||||
TagIDs []int `json:"tag_ids"`
|
||||
PerformerIDs []int `json:"performer_ids"`
|
||||
SceneIDs RelatedIDs `json:"scene_ids"`
|
||||
TagIDs RelatedIDs `json:"tag_ids"`
|
||||
PerformerIDs RelatedIDs `json:"performer_ids"`
|
||||
}
|
||||
|
||||
func (g *Gallery) LoadSceneIDs(ctx context.Context, l SceneIDLoader) error {
|
||||
return g.SceneIDs.load(func() ([]int, error) {
|
||||
return l.GetSceneIDs(ctx, g.ID)
|
||||
})
|
||||
}
|
||||
|
||||
func (g *Gallery) LoadPerformerIDs(ctx context.Context, l PerformerIDLoader) error {
|
||||
return g.PerformerIDs.load(func() ([]int, error) {
|
||||
return l.GetPerformerIDs(ctx, g.ID)
|
||||
})
|
||||
}
|
||||
|
||||
func (g *Gallery) LoadTagIDs(ctx context.Context, l TagIDLoader) error {
|
||||
return g.TagIDs.load(func() ([]int, error) {
|
||||
return l.GetTagIDs(ctx, g.ID)
|
||||
})
|
||||
}
|
||||
|
||||
func (g Gallery) PrimaryFile() file.File {
|
||||
|
||||
Reference in New Issue
Block a user