mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
Model refactor (#3915)
* Add mockery config file * Move basic file/folder structs to models * Fix hack due to import loop * Move file interfaces to models * Move folder interfaces to models * Move scene interfaces to models * Move scene marker interfaces to models * Move image interfaces to models * Move gallery interfaces to models * Move gallery chapter interfaces to models * Move studio interfaces to models * Move movie interfaces to models * Move performer interfaces to models * Move tag interfaces to models * Move autotag interfaces to models * Regenerate mocks
This commit is contained in:
@@ -7,27 +7,28 @@ import (
|
||||
"io/fs"
|
||||
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
)
|
||||
|
||||
type folderRenameCandidate struct {
|
||||
folder *Folder
|
||||
folder *models.Folder
|
||||
found int
|
||||
files int
|
||||
}
|
||||
|
||||
type folderRenameDetector struct {
|
||||
// candidates is a map of folder id to the number of files that match
|
||||
candidates map[FolderID]folderRenameCandidate
|
||||
candidates map[models.FolderID]folderRenameCandidate
|
||||
// rejects is a set of folder ids which were found to still exist
|
||||
rejects map[FolderID]struct{}
|
||||
rejects map[models.FolderID]struct{}
|
||||
}
|
||||
|
||||
func (d *folderRenameDetector) isReject(id FolderID) bool {
|
||||
func (d *folderRenameDetector) isReject(id models.FolderID) bool {
|
||||
_, ok := d.rejects[id]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (d *folderRenameDetector) getCandidate(id FolderID) *folderRenameCandidate {
|
||||
func (d *folderRenameDetector) getCandidate(id models.FolderID) *folderRenameCandidate {
|
||||
c, ok := d.candidates[id]
|
||||
if !ok {
|
||||
return nil
|
||||
@@ -40,14 +41,14 @@ func (d *folderRenameDetector) setCandidate(c folderRenameCandidate) {
|
||||
d.candidates[c.folder.ID] = c
|
||||
}
|
||||
|
||||
func (d *folderRenameDetector) reject(id FolderID) {
|
||||
func (d *folderRenameDetector) reject(id models.FolderID) {
|
||||
d.rejects[id] = struct{}{}
|
||||
}
|
||||
|
||||
// bestCandidate returns the folder that is the best candidate for a rename.
|
||||
// This is the folder that has the largest number of its original files that
|
||||
// are still present in the new location.
|
||||
func (d *folderRenameDetector) bestCandidate() *Folder {
|
||||
func (d *folderRenameDetector) bestCandidate() *models.Folder {
|
||||
if len(d.candidates) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -74,14 +75,14 @@ func (d *folderRenameDetector) bestCandidate() *Folder {
|
||||
return best.folder
|
||||
}
|
||||
|
||||
func (s *scanJob) detectFolderMove(ctx context.Context, file scanFile) (*Folder, error) {
|
||||
func (s *scanJob) detectFolderMove(ctx context.Context, file scanFile) (*models.Folder, error) {
|
||||
// in order for a folder to be considered moved, the existing folder must be
|
||||
// missing, and the majority of the old folder's files must be present, unchanged,
|
||||
// in the new folder.
|
||||
|
||||
detector := folderRenameDetector{
|
||||
candidates: make(map[FolderID]folderRenameCandidate),
|
||||
rejects: make(map[FolderID]struct{}),
|
||||
candidates: make(map[models.FolderID]folderRenameCandidate),
|
||||
rejects: make(map[models.FolderID]struct{}),
|
||||
}
|
||||
// rejects is a set of folder ids which were found to still exist
|
||||
|
||||
@@ -117,7 +118,7 @@ func (s *scanJob) detectFolderMove(ctx context.Context, file scanFile) (*Folder,
|
||||
}
|
||||
|
||||
// check if the file exists in the database based on basename, size and mod time
|
||||
existing, err := s.Repository.Store.FindByFileInfo(ctx, info, size)
|
||||
existing, err := s.Repository.FileStore.FindByFileInfo(ctx, info, size)
|
||||
if err != nil {
|
||||
return fmt.Errorf("checking for existing file %q: %w", path, err)
|
||||
}
|
||||
@@ -163,7 +164,7 @@ func (s *scanJob) detectFolderMove(ctx context.Context, file scanFile) (*Folder,
|
||||
|
||||
// parent folder is missing, possible candidate
|
||||
// count the total number of files in the existing folder
|
||||
count, err := s.Repository.Store.CountByFolderID(ctx, parentFolderID)
|
||||
count, err := s.Repository.FileStore.CountByFolderID(ctx, parentFolderID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("counting files in folder %d: %w", parentFolderID, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user