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
+18
View File
@@ -2,6 +2,7 @@ package persistence
import (
"errors"
"github.com/deluan/gosonic/domain"
)
@@ -40,4 +41,21 @@ func (r *albumRepository) GetAll(options domain.QueryOptions) (domain.Albums, er
return as, err
}
func (r *albumRepository) PurgeInactive(active *domain.Albums) 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.AlbumRepository = (*albumRepository)(nil)