Refactored PurgeInactive as a "generic" function.

Also delete indexes when removing records
This commit is contained in:
Deluan
2016-03-18 19:32:49 -04:00
parent cac352b18c
commit 3790aa45e4
11 changed files with 57 additions and 75 deletions
+4 -15
View File
@@ -43,21 +43,10 @@ func (r *mediaFileRepository) FindByAlbum(albumId string) (*domain.MediaFiles, e
return &mfs, err
}
func (r *mediaFileRepository) PurgeInactive(active *domain.MediaFiles) error {
currentIds, err := r.getAllIds()
if err != nil {
return err
}
for _, a := range *active {
currentIds[a.Id] = false
}
inactiveIds := make(map[string]bool)
for id, inactive := range currentIds {
if inactive {
inactiveIds[id] = true
}
}
return r.DeleteAll(inactiveIds)
func (r *mediaFileRepository) PurgeInactive(active domain.MediaFiles) error {
return r.purgeInactive(active, func(e interface{}) string {
return e.(domain.MediaFile).Id
})
}
var _ domain.MediaFileRepository = (*mediaFileRepository)(nil)