mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-01 19:47:37 +03:00
chore(server): add logs to begin/end transaction
Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
parent
15a3d2ca66
commit
5fa19f9cfa
8 changed files with 29 additions and 15 deletions
|
@ -41,6 +41,6 @@ type DataStore interface {
|
|||
|
||||
Resource(ctx context.Context, model interface{}) ResourceRepository
|
||||
|
||||
WithTx(func(tx DataStore) error) error
|
||||
WithTx(block func(tx DataStore) error, scope ...string) error
|
||||
GC(ctx context.Context) error
|
||||
}
|
||||
|
|
|
@ -118,14 +118,28 @@ func (s *SQLStore) Resource(ctx context.Context, m interface{}) model.ResourceRe
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *SQLStore) WithTx(block func(tx model.DataStore) error) error {
|
||||
conn, ok := s.db.(*dbx.DB)
|
||||
if !ok {
|
||||
func (s *SQLStore) WithTx(block func(tx model.DataStore) error, scope ...string) error {
|
||||
var msg string
|
||||
if len(scope) > 0 {
|
||||
msg = scope[0]
|
||||
}
|
||||
start := time.Now()
|
||||
conn, inTx := s.db.(*dbx.DB)
|
||||
if !inTx {
|
||||
log.Trace("Nested Transaction started", "scope", msg)
|
||||
conn = dbx.NewFromDB(db.Db(), db.Driver)
|
||||
} else {
|
||||
log.Trace("Transaction started", "scope", msg)
|
||||
}
|
||||
return conn.Transactional(func(tx *dbx.Tx) error {
|
||||
newDb := &SQLStore{db: tx}
|
||||
return block(newDb)
|
||||
err := block(newDb)
|
||||
if !inTx {
|
||||
log.Trace("Nested Transaction finished", "scope", msg, "elapsed", time.Since(start), err)
|
||||
} else {
|
||||
log.Trace("Transaction finished", "scope", msg, "elapsed", time.Since(start), err)
|
||||
}
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -390,7 +390,7 @@ func (p *phaseFolders) persistChanges(entry *folderEntry) (*folderEntry, error)
|
|||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}, "scanner: persist changes")
|
||||
if err != nil {
|
||||
log.Error(p.ctx, "Scanner: Error persisting changes to DB", "folder", entry.path, err)
|
||||
}
|
||||
|
@ -464,7 +464,7 @@ func (p *phaseFolders) finalize(err error) error {
|
|||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}, "scanner: finalize phaseFolders")
|
||||
return errors.Join(err, errF)
|
||||
}
|
||||
|
||||
|
|
|
@ -159,7 +159,7 @@ func (p *phaseMissingTracks) processMissingTracks(in *missingTracks) (*missingTr
|
|||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}, "scanner: process missing tracks")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ func (p *phaseRefreshAlbums) refreshAlbum(album *model.Album) (*model.Album, err
|
|||
p.refreshed.Add(1)
|
||||
p.state.changesDetected.Store(true)
|
||||
return nil
|
||||
})
|
||||
}, "scanner: refresh album")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -153,5 +153,5 @@ func (p *phaseRefreshAlbums) finalize(err error) error {
|
|||
log.Debug(p.ctx, "Scanner: Refreshed artist annotations", "artists", cnt, "elapsed", time.Since(start))
|
||||
p.state.changesDetected.Store(true)
|
||||
return nil
|
||||
})
|
||||
}, "scanner: finalize phaseRefreshAlbums")
|
||||
}
|
||||
|
|
|
@ -128,7 +128,7 @@ func (s *scannerImpl) runGC(ctx context.Context, state *scanState) func() error
|
|||
log.Debug(ctx, "Scanner: No changes detected, skipping GC")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}, "scanner: GC")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,7 +155,7 @@ func (s *scannerImpl) runRefreshStats(ctx context.Context, state *scanState) fun
|
|||
}
|
||||
log.Debug(ctx, "Scanner: Updated tag counts", "elapsed", time.Since(start))
|
||||
return nil
|
||||
})
|
||||
}, "scanner: refresh stats")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -189,7 +189,7 @@ func (s *scannerImpl) runUpdateLibraries(ctx context.Context, libs model.Librari
|
|||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}, "scanner: update libraries")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ func initialSetup(ds model.DataStore) {
|
|||
|
||||
err = properties.Put(consts.InitialSetupFlagKey, time.Now().String())
|
||||
return err
|
||||
})
|
||||
}, "initial setup")
|
||||
}
|
||||
|
||||
// If the Dev Admin user is not present, create it
|
||||
|
|
|
@ -209,7 +209,7 @@ func (db *MockDataStore) Radio(ctx context.Context) model.RadioRepository {
|
|||
return db.MockedRadio
|
||||
}
|
||||
|
||||
func (db *MockDataStore) WithTx(block func(model.DataStore) error) error {
|
||||
func (db *MockDataStore) WithTx(block func(tx model.DataStore) error, label ...string) error {
|
||||
return block(db)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue