🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
refactor:clean annotations in GC
Deluan0d0787e6561d
diff --git a/persistence/persistence.go b/persistence/persistence.goindex 65ccadcf4..9d1766ba2 100644--- a/persistence/persistence.go+++ b/persistence/persistence.go@@ -126,7 +126,19 @@ func (db *NewSQLStore) GC(ctx context.Context) error {if err != nil {return err}- return db.Artist(ctx).(*artistRepository).cleanSearchIndex()+ err = db.Artist(ctx).(*artistRepository).cleanSearchIndex()+ if err != nil {+ return err+ }+ err = db.MediaFile(ctx).(*mediaFileRepository).cleanAnnotations()+ if err != nil {+ return err+ }+ err = db.Album(ctx).(*albumRepository).cleanAnnotations()+ if err != nil {+ return err+ }+ return db.Artist(ctx).(*artistRepository).cleanAnnotations()}func (db *NewSQLStore) getOrmer() orm.Ormer {diff --git a/persistence/annotation.go b/persistence/sql_annotations.gosimilarity index 87%rename from persistence/annotation.gorename to persistence/sql_annotations.goindex 7a2607d3b..298cc23cc 100644--- a/persistence/annotation.go+++ b/persistence/sql_annotations.go@@ -5,6 +5,7 @@ import (. "github.com/Masterminds/squirrel""github.com/astaxie/beego/orm"+ "github.com/deluan/navidrome/log""github.com/deluan/navidrome/model""github.com/google/uuid")@@ -95,3 +96,15 @@ func (r sqlRepository) SetStar(starred bool, ids ...string) error {func (r sqlRepository) SetRating(rating int, itemID string) error {return r.annUpsert(map[string]interface{}{"rating": rating}, itemID)}++func (r sqlRepository) cleanAnnotations() error {+ del := Delete(annotationTable).Where(Eq{"item_type": r.tableName}).Where("item_id not in (select id from " + r.tableName + ")")+ c, err := r.executeSQL(del)+ if err != nil {+ return err+ }+ if c > 0 {+ log.Debug(r.ctx, "Clean-up annotations", "table", r.tableName, "totalDeleted", c)+ }+ return nil+}diff --git a/persistence/sql_repository.go b/persistence/sql_base_repository.gosimilarity index 100%rename from persistence/sql_repository.gorename to persistence/sql_base_repository.godiff --git a/persistence/search.go b/persistence/sql_search.gosimilarity index 100%rename from persistence/search.gorename to persistence/sql_search.go