refactor(scanner): simplify GC method by removing library ID parameter

Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
Deluan 2025-11-11 11:48:48 -05:00
parent 01f68f4a75
commit 33704edc1c
5 changed files with 6 additions and 12 deletions

View File

@ -373,10 +373,10 @@ type extendedDataStore struct {
gcError error
}
func (ds *extendedDataStore) GC(ctx context.Context, libraryIDs ...int) error {
func (ds *extendedDataStore) GC(ctx context.Context) error {
ds.gcCalled = true
if ds.gcError != nil {
return ds.gcError
}
return ds.MockDataStore.GC(ctx, libraryIDs...)
return ds.MockDataStore.GC(ctx)
}

View File

@ -43,5 +43,5 @@ type DataStore interface {
WithTx(block func(tx DataStore) error, scope ...string) error
WithTxImmediate(block func(tx DataStore) error, scope ...string) error
GC(ctx context.Context, libraryIDs ...int) error
GC(ctx context.Context) error
}

View File

@ -157,7 +157,7 @@ func (s *SQLStore) WithTxImmediate(block func(tx model.DataStore) error, scope .
}, scope...)
}
func (s *SQLStore) GC(ctx context.Context, libraryIDs ...int) error {
func (s *SQLStore) GC(ctx context.Context) error {
trace := func(ctx context.Context, msg string, f func() error) func() error {
return func() error {
start := time.Now()
@ -167,12 +167,6 @@ func (s *SQLStore) GC(ctx context.Context, libraryIDs ...int) error {
}
}
// TODO: Implement library-specific filtering for GC operations
// For now, GC runs globally even in selective scans
if len(libraryIDs) > 0 {
log.Debug(ctx, "GC: Running with library filter (not implemented)", "libraries", libraryIDs)
}
err := run.Sequentially(
trace(ctx, "purge empty albums", func() error { return s.Album(ctx).(*albumRepository).purgeEmpty() }),
trace(ctx, "purge empty artists", func() error { return s.Artist(ctx).(*artistRepository).purgeEmpty() }),

View File

@ -187,7 +187,7 @@ func (s *scannerImpl) runGC(ctx context.Context, state *scanState) func() error
return s.ds.WithTx(func(tx model.DataStore) error {
if state.changesDetected.Load() {
start := time.Now()
err := tx.GC(ctx, state.affectedLibIDs...)
err := tx.GC(ctx)
if err != nil {
log.Error(ctx, "Scanner: Error running GC", err)
return fmt.Errorf("running GC: %w", err)

View File

@ -258,6 +258,6 @@ func (db *MockDataStore) Resource(ctx context.Context, m any) model.ResourceRepo
}
}
func (db *MockDataStore) GC(context.Context, ...int) error {
func (db *MockDataStore) GC(context.Context) error {
return nil
}