mirror of
https://github.com/navidrome/navidrome.git
synced 2025-06-04 17:41:15 +03:00
Small refactorings, better var/function names
This commit is contained in:
parent
ddb30ceb11
commit
4e4fcb2304
@ -50,7 +50,7 @@ func (s *TagScanner2) Scan(ctx context.Context, lastModifiedSince time.Time) err
|
|||||||
ctx = s.withAdminUser(ctx)
|
ctx = s.withAdminUser(ctx)
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
allDirs, err := s.getDirTree(ctx)
|
allFSDirs, err := s.getDirTree(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -60,8 +60,8 @@ func (s *TagScanner2) Scan(ctx context.Context, lastModifiedSince time.Time) err
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
changedDirs := s.getChangedDirs(ctx, allDirs, allDBDirs, lastModifiedSince)
|
changedDirs := s.getChangedDirs(ctx, allFSDirs, allDBDirs, lastModifiedSince)
|
||||||
deletedDirs := s.getDeletedDirs(ctx, allDirs, allDBDirs)
|
deletedDirs := s.getDeletedDirs(ctx, allFSDirs, allDBDirs)
|
||||||
|
|
||||||
if len(changedDirs)+len(deletedDirs) == 0 {
|
if len(changedDirs)+len(deletedDirs) == 0 {
|
||||||
log.Debug(ctx, "No changes found in Music Folder", "folder", s.rootFolder)
|
log.Debug(ctx, "No changes found in Music Folder", "folder", s.rootFolder)
|
||||||
@ -94,7 +94,7 @@ func (s *TagScanner2) Scan(ctx context.Context, lastModifiedSince time.Time) err
|
|||||||
u, _ := request.UserFrom(ctx)
|
u, _ := request.UserFrom(ctx)
|
||||||
plsCount := 0
|
plsCount := 0
|
||||||
for _, dir := range changedDirs {
|
for _, dir := range changedDirs {
|
||||||
info := allDirs[dir]
|
info := allFSDirs[dir]
|
||||||
if info.hasPlaylist {
|
if info.hasPlaylist {
|
||||||
if !u.IsAdmin {
|
if !u.IsAdmin {
|
||||||
log.Warn("Playlists will not be imported, as there are no admin users yet, "+
|
log.Warn("Playlists will not be imported, as there are no admin users yet, "+
|
||||||
@ -141,18 +141,14 @@ func (s *TagScanner2) getDBDirTree(ctx context.Context) (map[string]struct{}, er
|
|||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TagScanner2) getChangedDirs(ctx context.Context, dirs dirMap, dbDirs map[string]struct{}, lastModified time.Time) []string {
|
func (s *TagScanner2) getChangedDirs(ctx context.Context, fsDirs dirMap, dbDirs map[string]struct{}, lastModified time.Time) []string {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
log.Trace(ctx, "Checking for changed folders")
|
log.Trace(ctx, "Checking for changed folders")
|
||||||
var changed []string
|
var changed []string
|
||||||
|
|
||||||
for d, info := range dirs {
|
for d, info := range fsDirs {
|
||||||
_, inDB := dbDirs[d]
|
_, inDB := dbDirs[d]
|
||||||
if !inDB && (info.hasAudioFiles) {
|
if (!inDB && (info.hasAudioFiles)) || info.modTime.After(lastModified) {
|
||||||
changed = append(changed, d)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if info.modTime.After(lastModified) {
|
|
||||||
changed = append(changed, d)
|
changed = append(changed, d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -162,13 +158,13 @@ func (s *TagScanner2) getChangedDirs(ctx context.Context, dirs dirMap, dbDirs ma
|
|||||||
return changed
|
return changed
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TagScanner2) getDeletedDirs(ctx context.Context, allDirs dirMap, dbDirs map[string]struct{}) []string {
|
func (s *TagScanner2) getDeletedDirs(ctx context.Context, fsDirs dirMap, dbDirs map[string]struct{}) []string {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
log.Trace(ctx, "Checking for deleted folders")
|
log.Trace(ctx, "Checking for deleted folders")
|
||||||
var deleted []string
|
var deleted []string
|
||||||
|
|
||||||
for d := range dbDirs {
|
for d := range dbDirs {
|
||||||
if _, ok := allDirs[d]; !ok {
|
if _, ok := fsDirs[d]; !ok {
|
||||||
deleted = append(deleted, d)
|
deleted = append(deleted, d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ func (c *MediaAnnotationController) Star(w http.ResponseWriter, r *http.Request)
|
|||||||
ids = append(ids, albumIds...)
|
ids = append(ids, albumIds...)
|
||||||
ids = append(ids, artistIds...)
|
ids = append(ids, artistIds...)
|
||||||
|
|
||||||
err := c.star(r.Context(), true, ids...)
|
err := c.setStar(r.Context(), true, ids...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ func (c *MediaAnnotationController) Star(w http.ResponseWriter, r *http.Request)
|
|||||||
return NewResponse(), nil
|
return NewResponse(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MediaAnnotationController) star(ctx context.Context, starred bool, ids ...string) error {
|
func (c *MediaAnnotationController) setStar(ctx context.Context, starred bool, ids ...string) error {
|
||||||
if len(ids) == 0 {
|
if len(ids) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -94,7 +94,7 @@ func (c *MediaAnnotationController) Unstar(w http.ResponseWriter, r *http.Reques
|
|||||||
ids = append(ids, albumIds...)
|
ids = append(ids, albumIds...)
|
||||||
ids = append(ids, artistIds...)
|
ids = append(ids, artistIds...)
|
||||||
|
|
||||||
err := c.star(r.Context(), false, ids...)
|
err := c.setStar(r.Context(), false, ids...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user