Skip to content

🎧 Your Personal Streaming Service

Remove unused PurgeInactive methods

Deluan6785d616d0e8
diff --git a/model/album.go b/model/album.go
index 3b4345c63..bb9bb3041 100644
--- a/model/album.go
+++ b/model/album.go
@@ -33,7 +33,6 @@ type AlbumRepository interface {
Get(id string) (*Album, error)
FindByArtist(artistId string) (Albums, error)
GetAll(...QueryOptions) (Albums, error)
- PurgeInactive(active Albums) error
GetAllIds() ([]string, error)
GetStarred(...QueryOptions) (Albums, error)
Search(q string, offset int, size int) (Albums, error)
diff --git a/model/artist.go b/model/artist.go
index ef4b16152..b084ca6c5 100644
--- a/model/artist.go
+++ b/model/artist.go
@@ -22,7 +22,6 @@ type ArtistRepository interface {
Exists(id string) (bool, error)
Put(m *Artist) error
Get(id string) (*Artist, error)
- PurgeInactive(active Artists) error
GetStarred(...QueryOptions) (Artists, error)
SetStar(star bool, ids ...string) error
Search(q string, offset int, size int) (Artists, error)
diff --git a/model/mediafile.go b/model/mediafile.go
index a3d96807a..07b72f68a 100644
--- a/model/mediafile.go
+++ b/model/mediafile.go
@@ -47,7 +47,6 @@ type MediaFileRepository interface {
FindByAlbum(albumId string) (MediaFiles, error)
FindByPath(path string) (MediaFiles, error)
GetStarred(options ...QueryOptions) (MediaFiles, error)
- PurgeInactive(active MediaFiles) error
GetAllIds() ([]string, error)
Search(q string, offset int, size int) (MediaFiles, error)
Delete(id string) error
diff --git a/model/playlist.go b/model/playlist.go
index 6580e6667..06c9b6e37 100644
--- a/model/playlist.go
+++ b/model/playlist.go
@@ -17,7 +17,6 @@ type PlaylistRepository interface {
Put(m *Playlist) error
Get(id string) (*Playlist, error)
GetAll(options ...QueryOptions) (Playlists, error)
- PurgeInactive(active Playlists) ([]string, error)
}
type Playlists []Playlist
diff --git a/persistence/album_repository.go b/persistence/album_repository.go
index defc2ba49..f5e402e88 100644
--- a/persistence/album_repository.go
+++ b/persistence/album_repository.go
@@ -151,13 +151,6 @@ group by album_id order by f.id`, strings.Join(ids, "','"))
return err
}
-func (r *albumRepository) PurgeInactive(activeList model.Albums) error {
- _, err := r.purgeInactive(activeList, func(item interface{}) string {
- return item.(model.Album).ID
- })
- return err
-}
-
func (r *albumRepository) PurgeEmpty() error {
_, err := r.ormer.Raw("delete from album where id not in (select distinct(album_id) from media_file)").Exec()
return err
diff --git a/persistence/artist_repository.go b/persistence/artist_repository.go
index f17e223ec..15392ab80 100644
--- a/persistence/artist_repository.go
+++ b/persistence/artist_repository.go
@@ -179,13 +179,6 @@ func (r *artistRepository) SetStar(starred bool, ids ...string) error {
return err
}
-func (r *artistRepository) PurgeInactive(activeList model.Artists) error {
- _, err := r.purgeInactive(activeList, func(item interface{}) string {
- return item.(model.Artist).ID
- })
- return err
-}
-
func (r *artistRepository) PurgeEmpty() error {
_, err := r.ormer.Raw("delete from artist where id not in (select distinct(artist_id) from album)").Exec()
return err
diff --git a/persistence/artist_repository_test.go b/persistence/artist_repository_test.go
index 60ed8d63f..1c974c680 100644
--- a/persistence/artist_repository_test.go
+++ b/persistence/artist_repository_test.go
@@ -56,30 +56,4 @@ var _ = Describe("ArtistRepository", func() {
}))
})
})
-
- Describe("PurgeInactive", func() {
- BeforeEach(func() {
- for _, a := range testArtists {
- repo.Put(&a)
- }
- })
-
- It("purges inactive records", func() {
- active := model.Artists{{ID: "1"}, {ID: "3"}}
-
- Expect(repo.PurgeInactive(active)).To(BeNil())
-
- Expect(repo.CountAll()).To(Equal(int64(2)))
- Expect(repo.Exists("2")).To(BeFalse())
- })
-
- It("doesn't delete anything if all is active", func() {
- active := model.Artists{{ID: "1"}, {ID: "2"}, {ID: "3"}}
-
- Expect(repo.PurgeInactive(active)).To(BeNil())
-
- Expect(repo.CountAll()).To(Equal(int64(3)))
- Expect(repo.Exists("1")).To(BeTrue())
- })
- })
})
diff --git a/persistence/mediafile_repository.go b/persistence/mediafile_repository.go
index 2bde5af01..58489a27c 100644
--- a/persistence/mediafile_repository.go
+++ b/persistence/mediafile_repository.go
@@ -170,13 +170,6 @@ func (r *mediaFileRepository) MarkAsPlayed(id string, playDate time.Time) error
return err
}
-func (r *mediaFileRepository) PurgeInactive(activeList model.MediaFiles) error {
- _, err := r.purgeInactive(activeList, func(item interface{}) string {
- return item.(model.MediaFile).ID
- })
- return err
-}
-
func (r *mediaFileRepository) Search(q string, offset int, size int) (model.MediaFiles, error) {
if len(q) <= 2 {
return nil, nil
diff --git a/persistence/playlist_repository.go b/persistence/playlist_repository.go
index 39ec75d74..e9701a10a 100644
--- a/persistence/playlist_repository.go
+++ b/persistence/playlist_repository.go
@@ -64,13 +64,6 @@ func (r *playlistRepository) toPlaylists(all []playlist) (model.Playlists, error
return result, nil
}
-func (r *playlistRepository) PurgeInactive(activeList model.Playlists) ([]string, error) {
- _, err := r.purgeInactive(activeList, func(item interface{}) string {
- return item.(model.Playlist).ID
- })
- return nil, err
-}
-
func (r *playlistRepository) toDomain(p *playlist) model.Playlist {
return model.Playlist{
ID: p.ID,
diff --git a/persistence/searchable_repository.go b/persistence/searchable_repository.go
index 245ffbcff..940f2f676 100644
--- a/persistence/searchable_repository.go
+++ b/persistence/searchable_repository.go
@@ -46,14 +46,6 @@ func (r *searchableRepository) put(id string, textToIndex string, a interface{},
return r.addToIndex(r.tableName, id, textToIndex)
}
-func (r *searchableRepository) purgeInactive(activeList interface{}, getId func(item interface{}) string) ([]string, error) {
- idsToDelete, err := r.sqlRepository.purgeInactive(activeList, getId)
- if err != nil {
- return nil, err
- }
- return idsToDelete, r.removeFromIndex(r.tableName, idsToDelete)
-}
-
func (r *searchableRepository) addToIndex(table, id, text string) error {
item := search{ID: id, Table: table}
err := r.ormer.Read(&item)
diff --git a/persistence/sql_repository.go b/persistence/sql_repository.go
index 49801077e..c8a976343 100644
--- a/persistence/sql_repository.go
+++ b/persistence/sql_repository.go
@@ -2,7 +2,6 @@ package persistence
import (
"github.com/astaxie/beego/orm"
- "github.com/cloudsonic/sonic-server/log"
"github.com/cloudsonic/sonic-server/model"
)
@@ -122,31 +121,3 @@ func (r *sqlRepository) DeleteAll() error {
_, err := r.newQuery().Filter("id__isnull", false).Delete()
return err
}
-
-func (r *sqlRepository) purgeInactive(activeList interface{}, getId func(item interface{}) string) ([]string, error) {
- allIds, err := r.GetAllIds()
- if err != nil {
- return nil, err
- }
- activeIds := collectField(activeList, getId)
- idsToDelete := difference(allIds, activeIds)
- if len(idsToDelete) == 0 {
- return nil, nil
- }
- log.Debug("Purging inactive records", "table", r.tableName, "total", len(idsToDelete))
-
- var offset int
- for {
- var subset = paginateSlice(idsToDelete, offset, batchSize)
- if len(subset) == 0 {
- break
- }
- log.Trace("-- Purging inactive records", "table", r.tableName, "num", len(subset), "from", offset)
- offset += len(subset)
- _, err := r.newQuery().Filter("id__in", subset).Delete()
- if err != nil {
- return nil, err
- }
- }
- return idsToDelete, nil
-}