mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 12:54:38 +03:00
[Files Refactor] Performance tuning (#2865)
* Don't load image files by default * Don't load gallery files by default * Don't load scene files by default * Retry locked transactions forever * Don't show release notes if config not loaded * Don't translate path slashes in export
This commit is contained in:
@@ -2,7 +2,6 @@ package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
@@ -11,10 +10,6 @@ import (
|
||||
type Gallery struct {
|
||||
ID int `json:"id"`
|
||||
|
||||
// Path *string `json:"path"`
|
||||
// Checksum string `json:"checksum"`
|
||||
// Zip bool `json:"zip"`
|
||||
|
||||
Title string `json:"title"`
|
||||
URL string `json:"url"`
|
||||
Date *Date `json:"date"`
|
||||
@@ -23,16 +18,15 @@ type Gallery struct {
|
||||
Organized bool `json:"organized"`
|
||||
StudioID *int `json:"studio_id"`
|
||||
|
||||
// FileModTime *time.Time `json:"file_mod_time"`
|
||||
|
||||
// transient - not persisted
|
||||
Files []file.File
|
||||
Files RelatedFiles
|
||||
// transient - not persisted
|
||||
PrimaryFileID *file.ID
|
||||
// transient - path of primary file or folder
|
||||
Path string
|
||||
|
||||
FolderID *file.FolderID `json:"folder_id"`
|
||||
|
||||
// transient - not persisted
|
||||
FolderPath string `json:"folder_path"`
|
||||
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
@@ -41,6 +35,30 @@ type Gallery struct {
|
||||
PerformerIDs RelatedIDs `json:"performer_ids"`
|
||||
}
|
||||
|
||||
func (g *Gallery) LoadFiles(ctx context.Context, l FileLoader) error {
|
||||
return g.Files.load(func() ([]file.File, error) {
|
||||
return l.GetFiles(ctx, g.ID)
|
||||
})
|
||||
}
|
||||
|
||||
func (g *Gallery) LoadPrimaryFile(ctx context.Context, l file.Finder) error {
|
||||
return g.Files.loadPrimary(func() (file.File, error) {
|
||||
if g.PrimaryFileID == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
f, err := l.Find(ctx, *g.PrimaryFileID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(f) > 0 {
|
||||
return f[0], nil
|
||||
}
|
||||
return nil, nil
|
||||
})
|
||||
}
|
||||
|
||||
func (g *Gallery) LoadSceneIDs(ctx context.Context, l SceneIDLoader) error {
|
||||
return g.SceneIDs.load(func() ([]int, error) {
|
||||
return l.GetSceneIDs(ctx, g.ID)
|
||||
@@ -59,24 +77,8 @@ func (g *Gallery) LoadTagIDs(ctx context.Context, l TagIDLoader) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (g Gallery) PrimaryFile() file.File {
|
||||
if len(g.Files) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return g.Files[0]
|
||||
}
|
||||
|
||||
func (g Gallery) Path() string {
|
||||
if p := g.PrimaryFile(); p != nil {
|
||||
return p.Base().Path
|
||||
}
|
||||
|
||||
return g.FolderPath
|
||||
}
|
||||
|
||||
func (g Gallery) Checksum() string {
|
||||
if p := g.PrimaryFile(); p != nil {
|
||||
if p := g.Files.Primary(); p != nil {
|
||||
v := p.Base().Fingerprints.Get(file.FingerprintTypeMD5)
|
||||
if v == nil {
|
||||
return ""
|
||||
@@ -123,15 +125,7 @@ func (g Gallery) GetTitle() string {
|
||||
return g.Title
|
||||
}
|
||||
|
||||
if len(g.Files) > 0 {
|
||||
return filepath.Base(g.Path())
|
||||
}
|
||||
|
||||
if g.FolderPath != "" {
|
||||
return g.FolderPath
|
||||
}
|
||||
|
||||
return ""
|
||||
return g.Path
|
||||
}
|
||||
|
||||
const DefaultGthumbWidth int = 640
|
||||
|
||||
Reference in New Issue
Block a user