Removing purged ids from the search index

This commit is contained in:
Deluan
2016-03-18 19:50:21 -04:00
parent 3790aa45e4
commit 508bf7152f
12 changed files with 44 additions and 22 deletions
+1 -1
View File
@@ -57,7 +57,7 @@ func (r *albumRepository) GetAllIds() (*[]string, error) {
return &ids, nil
}
func (r *albumRepository) PurgeInactive(active domain.Albums) error {
func (r *albumRepository) PurgeInactive(active domain.Albums) ([]string, error) {
return r.purgeInactive(active, func(e interface{}) string {
return e.(domain.Album).Id
})
+1 -1
View File
@@ -34,7 +34,7 @@ func (r *artistRepository) GetByName(name string) (*domain.Artist, error) {
return r.Get(id)
}
func (r *artistRepository) PurgeInactive(active domain.Artists) error {
func (r *artistRepository) PurgeInactive(active domain.Artists) ([]string, error) {
return r.purgeInactive(active, func(e interface{}) string {
return e.(domain.Artist).Id
})
+9 -8
View File
@@ -78,32 +78,33 @@ func (r *ledisRepository) getAllIds() (map[string]bool, error) {
type getIdFunc func(e interface{}) string
func (r *ledisRepository) purgeInactive(activeList interface{}, getId getIdFunc) error {
func (r *ledisRepository) purgeInactive(activeList interface{}, getId getIdFunc) ([]string, error) {
currentIds, err := r.getAllIds()
if err != nil {
return err
return nil, err
}
reflected := reflect.ValueOf(activeList).Elem()
for i := 0; i < reflected.Len(); i++ {
totalActive := reflected.Len()
for i := 0; i < totalActive; i++ {
a := reflected.Index(i)
id := getId(a.Interface())
currentIds[id] = false
}
inactiveIds := make(map[string]bool)
inactiveIds := make([]string, 0, len(currentIds)-totalActive)
for id, inactive := range currentIds {
if inactive {
inactiveIds[id] = true
inactiveIds = append(inactiveIds, id)
}
}
return r.removeAll(inactiveIds)
return inactiveIds, r.removeAll(inactiveIds)
}
func (r *ledisRepository) removeAll(ids map[string]bool) error {
func (r *ledisRepository) removeAll(ids []string) error {
allKey := r.table + "s:all"
keys := make([][]byte, len(ids))
i := 0
for id := range ids {
for _, id := range ids {
// Delete from parent:parentId:table (ZSet)
if r.parentTable != "" {
parentKey := []byte(fmt.Sprintf("%s:%s:%s", r.table, id, r.parentIdField))
+1 -2
View File
@@ -231,8 +231,7 @@ func TestBaseRepository(t *testing.T) {
})
Convey("When I call DeletaAll with one of the entities", func() {
ids := make(map[string]bool)
ids["1"] = true
ids := []string{"1"}
err := repo.removeAll(ids)
Convey("Then It should not return any error", func() {
So(err, ShouldBeNil)
+1 -1
View File
@@ -43,7 +43,7 @@ func (r *mediaFileRepository) FindByAlbum(albumId string) (*domain.MediaFiles, e
return &mfs, err
}
func (r *mediaFileRepository) PurgeInactive(active domain.MediaFiles) error {
func (r *mediaFileRepository) PurgeInactive(active domain.MediaFiles) ([]string, error) {
return r.purgeInactive(active, func(e interface{}) string {
return e.(domain.MediaFile).Id
})
+1 -1
View File
@@ -35,7 +35,7 @@ func (r *playlistRepository) GetAll(options domain.QueryOptions) (*domain.Playli
return &as, err
}
func (r *playlistRepository) PurgeInactive(active domain.Playlists) error {
func (r *playlistRepository) PurgeInactive(active domain.Playlists) ([]string, error) {
return r.purgeInactive(active, func(e interface{}) string {
return e.(domain.Playlist).Id
})