From 33704edc1c542081f1176790a225e99c23eb1d82 Mon Sep 17 00:00:00 2001 From: Deluan Date: Tue, 11 Nov 2025 11:48:48 -0500 Subject: [PATCH] refactor(scanner): simplify GC method by removing library ID parameter Signed-off-by: Deluan --- core/maintenance_test.go | 4 ++-- model/datastore.go | 2 +- persistence/persistence.go | 8 +------- scanner/scanner.go | 2 +- tests/mock_data_store.go | 2 +- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/core/maintenance_test.go b/core/maintenance_test.go index e83d1f8bd..8e8796ffa 100644 --- a/core/maintenance_test.go +++ b/core/maintenance_test.go @@ -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) } diff --git a/model/datastore.go b/model/datastore.go index 536a37274..4290e2134 100644 --- a/model/datastore.go +++ b/model/datastore.go @@ -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 } diff --git a/persistence/persistence.go b/persistence/persistence.go index 6db3f8575..ac607f85f 100644 --- a/persistence/persistence.go +++ b/persistence/persistence.go @@ -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() }), diff --git a/scanner/scanner.go b/scanner/scanner.go index 7b3c14d4b..be11ec5a3 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -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) diff --git a/tests/mock_data_store.go b/tests/mock_data_store.go index 2c0c90f62..56f68a74b 100644 --- a/tests/mock_data_store.go +++ b/tests/mock_data_store.go @@ -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 }