Remove unused PurgeInactive methods

This commit is contained in:
Deluan
2020-01-20 08:16:22 -05:00
parent c661ac8833
commit 6785d616d0
11 changed files with 0 additions and 95 deletions
-1
View File
@@ -33,7 +33,6 @@ type AlbumRepository interface {
Get(id string) (*Album, error) Get(id string) (*Album, error)
FindByArtist(artistId string) (Albums, error) FindByArtist(artistId string) (Albums, error)
GetAll(...QueryOptions) (Albums, error) GetAll(...QueryOptions) (Albums, error)
PurgeInactive(active Albums) error
GetAllIds() ([]string, error) GetAllIds() ([]string, error)
GetStarred(...QueryOptions) (Albums, error) GetStarred(...QueryOptions) (Albums, error)
Search(q string, offset int, size int) (Albums, error) Search(q string, offset int, size int) (Albums, error)
-1
View File
@@ -22,7 +22,6 @@ type ArtistRepository interface {
Exists(id string) (bool, error) Exists(id string) (bool, error)
Put(m *Artist) error Put(m *Artist) error
Get(id string) (*Artist, error) Get(id string) (*Artist, error)
PurgeInactive(active Artists) error
GetStarred(...QueryOptions) (Artists, error) GetStarred(...QueryOptions) (Artists, error)
SetStar(star bool, ids ...string) error SetStar(star bool, ids ...string) error
Search(q string, offset int, size int) (Artists, error) Search(q string, offset int, size int) (Artists, error)
-1
View File
@@ -47,7 +47,6 @@ type MediaFileRepository interface {
FindByAlbum(albumId string) (MediaFiles, error) FindByAlbum(albumId string) (MediaFiles, error)
FindByPath(path string) (MediaFiles, error) FindByPath(path string) (MediaFiles, error)
GetStarred(options ...QueryOptions) (MediaFiles, error) GetStarred(options ...QueryOptions) (MediaFiles, error)
PurgeInactive(active MediaFiles) error
GetAllIds() ([]string, error) GetAllIds() ([]string, error)
Search(q string, offset int, size int) (MediaFiles, error) Search(q string, offset int, size int) (MediaFiles, error)
Delete(id string) error Delete(id string) error
-1
View File
@@ -17,7 +17,6 @@ type PlaylistRepository interface {
Put(m *Playlist) error Put(m *Playlist) error
Get(id string) (*Playlist, error) Get(id string) (*Playlist, error)
GetAll(options ...QueryOptions) (Playlists, error) GetAll(options ...QueryOptions) (Playlists, error)
PurgeInactive(active Playlists) ([]string, error)
} }
type Playlists []Playlist type Playlists []Playlist
-7
View File
@@ -151,13 +151,6 @@ group by album_id order by f.id`, strings.Join(ids, "','"))
return err 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 { func (r *albumRepository) PurgeEmpty() error {
_, err := r.ormer.Raw("delete from album where id not in (select distinct(album_id) from media_file)").Exec() _, err := r.ormer.Raw("delete from album where id not in (select distinct(album_id) from media_file)").Exec()
return err return err
-7
View File
@@ -179,13 +179,6 @@ func (r *artistRepository) SetStar(starred bool, ids ...string) error {
return err 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 { func (r *artistRepository) PurgeEmpty() error {
_, err := r.ormer.Raw("delete from artist where id not in (select distinct(artist_id) from album)").Exec() _, err := r.ormer.Raw("delete from artist where id not in (select distinct(artist_id) from album)").Exec()
return err return err
-26
View File
@@ -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())
})
})
}) })
-7
View File
@@ -170,13 +170,6 @@ func (r *mediaFileRepository) MarkAsPlayed(id string, playDate time.Time) error
return err 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) { func (r *mediaFileRepository) Search(q string, offset int, size int) (model.MediaFiles, error) {
if len(q) <= 2 { if len(q) <= 2 {
return nil, nil return nil, nil
-7
View File
@@ -64,13 +64,6 @@ func (r *playlistRepository) toPlaylists(all []playlist) (model.Playlists, error
return result, nil 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 { func (r *playlistRepository) toDomain(p *playlist) model.Playlist {
return model.Playlist{ return model.Playlist{
ID: p.ID, ID: p.ID,
-8
View File
@@ -46,14 +46,6 @@ func (r *searchableRepository) put(id string, textToIndex string, a interface{},
return r.addToIndex(r.tableName, id, textToIndex) 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 { func (r *searchableRepository) addToIndex(table, id, text string) error {
item := search{ID: id, Table: table} item := search{ID: id, Table: table}
err := r.ormer.Read(&item) err := r.ormer.Read(&item)
-29
View File
@@ -2,7 +2,6 @@ package persistence
import ( import (
"github.com/astaxie/beego/orm" "github.com/astaxie/beego/orm"
"github.com/cloudsonic/sonic-server/log"
"github.com/cloudsonic/sonic-server/model" "github.com/cloudsonic/sonic-server/model"
) )
@@ -122,31 +121,3 @@ func (r *sqlRepository) DeleteAll() error {
_, err := r.newQuery().Filter("id__isnull", false).Delete() _, err := r.newQuery().Filter("id__isnull", false).Delete()
return err 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
}