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