Optimized import, only updating changed data and purging old data
This commit is contained in:
@@ -2,6 +2,7 @@ package persistence
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/deluan/gosonic/domain"
|
||||
)
|
||||
|
||||
@@ -33,4 +34,21 @@ func (r *artistRepository) GetByName(name string) (*domain.Artist, error) {
|
||||
return r.Get(id)
|
||||
}
|
||||
|
||||
func (r *artistRepository) PurgeInactive(active *domain.Artists) 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)
|
||||
}
|
||||
|
||||
var _ domain.ArtistRepository = (*artistRepository)(nil)
|
||||
|
||||
Reference in New Issue
Block a user