No files matched your search
@@ -127,15 +127,15 @@ func (db *DB) TransactionChunked(data []int64, cb func(*DB, []int64) error) erro
|
|||||||
}
|
}
|
||||||
// https://sqlite.org/limits.html
|
// https://sqlite.org/limits.html
|
||||||
const size = 999
|
const size = 999
|
||||||
return db.Transaction(func(tx *DB) error {
|
for i := 0; i < len(data); i += size {
|
||||||
for i := 0; i < len(data); i += size {
|
end := min(i+size, len(data))
|
||||||
end := min(i+size, len(data))
|
if err := db.Transaction(func(tx *DB) error {
|
||||||
if err := cb(tx, data[i:end]); err != nil {
|
return cb(tx, data[i:end])
|
||||||
return err
|
}); err != nil {
|
||||||
}
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
}
|
||||||
})
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type SettingKey string
|
type SettingKey string
|
||||||
|
|||||||
+19
-9
@@ -372,20 +372,30 @@ func (s *Scanner) scanDir(st *State, absPath string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// read tags outside the transaction to avoid holding db locks during disk i/o
|
||||||
|
type trackTagData struct {
|
||||||
|
trackUpdate
|
||||||
|
trprops tags.Properties
|
||||||
|
trags tags.Tags
|
||||||
|
}
|
||||||
|
tagData := make([]trackTagData, 0, len(trackUpdates))
|
||||||
|
for _, t := range trackUpdates {
|
||||||
|
trprops, trags, err := s.tagReader.Read(t.absPath)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("read %q: %w: %w", t.basename, err, ErrReadingTags)
|
||||||
|
}
|
||||||
|
tagData = append(tagData, trackTagData{trackUpdate: t, trprops: trprops, trags: trags})
|
||||||
|
}
|
||||||
|
|
||||||
return s.db.Transaction(func(tx *db.DB) error {
|
return s.db.Transaction(func(tx *db.DB) error {
|
||||||
var discTitles = map[int]string{}
|
var discTitles = map[int]string{}
|
||||||
for _, t := range trackUpdates {
|
for _, t := range tagData {
|
||||||
trprops, trags, err := s.tagReader.Read(t.absPath)
|
if err := s.populateTrackAndArtists(tx, st, t.i, &album, t.track, t.timeSpec, t.trprops, t.trags, t.basename, t.absPath); err != nil {
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("read %q: %w: %w", t.basename, err, ErrReadingTags)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := s.populateTrackAndArtists(tx, st, t.i, &album, t.track, t.timeSpec, trprops, trags, t.basename, t.absPath); err != nil {
|
|
||||||
return fmt.Errorf("populate track %q: %w", t.basename, err)
|
return fmt.Errorf("populate track %q: %w", t.basename, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
discNum := cmp.Or(tags.ParseInt(normtag.Get(trags, normtag.DiscNumber)), 1)
|
discNum := cmp.Or(tags.ParseInt(normtag.Get(t.trags, normtag.DiscNumber)), 1)
|
||||||
discSubtitle := normtag.Get(trags, "DISCSUBTITLE")
|
discSubtitle := normtag.Get(t.trags, "DISCSUBTITLE")
|
||||||
|
|
||||||
if _, exists := discTitles[discNum]; !exists && discSubtitle != "" {
|
if _, exists := discTitles[discNum]; !exists && discSubtitle != "" {
|
||||||
discTitles[discNum] = discSubtitle
|
discTitles[discNum] = discSubtitle
|
||||||
|
|||||||
Reference in New Issue
Block a user