Optimized import, only updating changed data and purging old data

This commit is contained in:
Deluan
2016-03-08 14:18:17 -05:00
parent df9687bf02
commit 46e7627fd3
13 changed files with 253 additions and 55 deletions
+19 -1
View File
@@ -2,8 +2,9 @@ package persistence
import (
"errors"
"github.com/deluan/gosonic/domain"
"sort"
"github.com/deluan/gosonic/domain"
)
type mediaFileRepository struct {
@@ -42,4 +43,21 @@ func (r *mediaFileRepository) FindByAlbum(albumId string) (domain.MediaFiles, er
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)
}
var _ domain.MediaFileRepository = (*mediaFileRepository)(nil)