From 74478ce6f9ba1c9c31c7929210f146ce50e0f264 Mon Sep 17 00:00:00 2001 From: Deluan Date: Tue, 1 Mar 2016 20:51:30 -0500 Subject: [PATCH] Sorting Artist Index on save --- repositories/index_repository.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/repositories/index_repository.go b/repositories/index_repository.go index 05adbdfd..ef02468c 100644 --- a/repositories/index_repository.go +++ b/repositories/index_repository.go @@ -27,6 +27,7 @@ func (r *artistIndex) Put(m *models.ArtistIndex) error { if m.Id == "" { return errors.New("Id is not set") } + sort.Sort(byArtistName(m.Artists)) return r.saveOrUpdate(m.Id, m) } @@ -39,16 +40,17 @@ func (r *artistIndex) Get(id string) (*models.ArtistIndex, error) { func (r *artistIndex) GetAll() ([]models.ArtistIndex, error) { var indices = make([]models.ArtistIndex, 0) err := r.loadAll(&indices, "") - if err == nil { - for _, idx := range indices { - sort.Sort(byArtistName(idx.Artists)) - } - } return indices, err } type byArtistName []models.ArtistInfo -func (a byArtistName) Len() int { return len(a) } -func (a byArtistName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a byArtistName) Less(i, j int) bool { return utils.NoArticle(a[i].Artist) < utils.NoArticle(a[j].Artist) } +func (a byArtistName) Len() int { + return len(a) +} +func (a byArtistName) Swap(i, j int) { + a[i], a[j] = a[j], a[i] +} +func (a byArtistName) Less(i, j int) bool { + return utils.NoArticle(a[i].Artist) < utils.NoArticle(a[j].Artist) +}