merge left and right paths for benchmark
This commit is contained in:
@@ -21,11 +21,9 @@ type Artist struct {
|
||||
type Track struct {
|
||||
IDBase
|
||||
CrudBase
|
||||
Folder Folder
|
||||
// TODO: try removing idx_folder_basename_ext
|
||||
FolderID int `gorm:"not null; unique_index:idx_folder_filename_ext" sql:"default: null; type:int REFERENCES folders(id) ON DELETE CASCADE"`
|
||||
Filename string `gorm:"not null; unique_index:idx_folder_filename_ext" sql:"default: null"`
|
||||
Ext string `gorm:"not nill; unique_index:idx_folder_filename_ext" sql:"default: null"`
|
||||
Folder Folder
|
||||
FolderID int `gorm:"not null; unique_index:idx_folder_filename" sql:"default: null; type:int REFERENCES folders(id) ON DELETE CASCADE"`
|
||||
Filename string `gorm:"not null; unique_index:idx_folder_filename" sql:"default: null"`
|
||||
Artist Artist
|
||||
ArtistID int `gorm:"not null; index" sql:"default: null; type:int REFERENCES artists(id) ON DELETE CASCADE"`
|
||||
ContentType string `gorm:"not null" sql:"default: null"`
|
||||
@@ -69,8 +67,7 @@ type Play struct {
|
||||
type Folder struct {
|
||||
IDBase
|
||||
CrudBase
|
||||
LeftPath string `gorm:"unique_index:idx_left_path_right_path"`
|
||||
RightPath string `gorm:"not null; unique_index:idx_left_path_right_path" sql:"default: null"`
|
||||
Path string `gorm:"not null; unique_index" sql:"default: null"`
|
||||
Parent *Folder
|
||||
ParentID int `sql:"default: null; type:int REFERENCES folders(id) ON DELETE CASCADE"`
|
||||
AlbumArtist Artist
|
||||
|
||||
@@ -34,7 +34,7 @@ func (s *folderStack) Peek() *model.Folder {
|
||||
func (s *folderStack) String() string {
|
||||
paths := make([]string, len(*s))
|
||||
for i, folder := range *s {
|
||||
paths[i] = folder.RightPath
|
||||
paths[i] = folder.Path
|
||||
}
|
||||
return fmt.Sprintf("[%s]", strings.Join(paths, " "))
|
||||
}
|
||||
|
||||
@@ -16,11 +16,10 @@ import (
|
||||
type item struct {
|
||||
//
|
||||
// common
|
||||
fullPath string
|
||||
relPath string
|
||||
directory string
|
||||
filename string
|
||||
stat os.FileInfo
|
||||
fullPath string
|
||||
relPath string
|
||||
filename string
|
||||
stat os.FileInfo
|
||||
//
|
||||
// track only
|
||||
ext string
|
||||
@@ -36,13 +35,12 @@ func (s *Scanner) callbackItem(fullPath string, info *godirwalk.Dirent) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "getting relative path")
|
||||
}
|
||||
directory, filename := path.Split(relPath)
|
||||
_, filename := path.Split(relPath)
|
||||
it := &item{
|
||||
fullPath: fullPath,
|
||||
relPath: relPath,
|
||||
directory: directory,
|
||||
filename: filename,
|
||||
stat: stat,
|
||||
fullPath: fullPath,
|
||||
relPath: relPath,
|
||||
filename: filename,
|
||||
stat: stat,
|
||||
}
|
||||
if info.IsDir() {
|
||||
return s.handleFolder(it)
|
||||
@@ -75,10 +73,7 @@ func (s *Scanner) callbackPost(fullPath string, info *godirwalk.Dirent) error {
|
||||
func (s *Scanner) handleFolder(it *item) error {
|
||||
var folder model.Folder
|
||||
err := s.tx.
|
||||
Where(model.Folder{
|
||||
LeftPath: it.directory,
|
||||
RightPath: it.filename,
|
||||
}).
|
||||
Where("path = ?", it.relPath).
|
||||
First(&folder).
|
||||
Error
|
||||
if !gorm.IsRecordNotFoundError(err) &&
|
||||
@@ -87,8 +82,7 @@ func (s *Scanner) handleFolder(it *item) error {
|
||||
s.curFolders.Push(&folder)
|
||||
return nil
|
||||
}
|
||||
folder.LeftPath = it.directory
|
||||
folder.RightPath = it.filename
|
||||
folder.Path = it.relPath
|
||||
s.tx.Save(&folder)
|
||||
folder.IsNew = true
|
||||
s.curFolders.Push(&folder)
|
||||
@@ -103,7 +97,6 @@ func (s *Scanner) handleTrack(it *item) error {
|
||||
Where(model.Track{
|
||||
FolderID: s.curFolderID(),
|
||||
Filename: it.filename,
|
||||
Ext: it.ext,
|
||||
}).
|
||||
First(&track).
|
||||
Error
|
||||
@@ -114,7 +107,6 @@ func (s *Scanner) handleTrack(it *item) error {
|
||||
return nil
|
||||
}
|
||||
track.Filename = it.filename
|
||||
track.Ext = it.ext
|
||||
track.ContentType = it.mime
|
||||
track.Size = int(it.stat.Size())
|
||||
track.FolderID = s.curFolderID()
|
||||
|
||||
Reference in New Issue
Block a user