🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Fix Genre field and Contains/NotContains/StartsWith/EndsWith in Criteria (Smart Playlists)
Deluan93ce0b5683b7
diff --git a/model/criteria/criteria_test.go b/model/criteria/criteria_test.goindex 26644c42f..5f43dc0e1 100644--- a/model/criteria/criteria_test.go+++ b/model/criteria/criteria_test.go@@ -62,7 +62,7 @@ var _ = Describe("Criteria", func() {It("generates valid SQL", func() {sql, args, err := goObj.ToSql()gomega.Expect(err).ToNot(gomega.HaveOccurred())- gomega.Expect(sql).To(gomega.Equal("(media_file.title ILIKE ? AND media_file.title NOT ILIKE ? AND (media_file.artist <> ? OR media_file.album = ?) AND (media_file.comment ILIKE ? AND (media_file.year >= ? AND media_file.year <= ?)))"))+ gomega.Expect(sql).To(gomega.Equal("(media_file.title LIKE ? AND media_file.title NOT LIKE ? AND (media_file.artist <> ? OR media_file.album = ?) AND (media_file.comment LIKE ? AND (media_file.year >= ? AND media_file.year <= ?)))"))gomega.Expect(args).To(gomega.ConsistOf("%love%", "%hate%", "u2", "best of", "this%", 1980, 1990))})diff --git a/model/criteria/operators.go b/model/criteria/operators.goindex 9db2f2233..ac81348bf 100644--- a/model/criteria/operators.go+++ b/model/criteria/operators.go@@ -99,7 +99,7 @@ func (af After) MarshalJSON() ([]byte, error) {type Contains map[string]interface{}func (ct Contains) ToSql() (sql string, args []interface{}, err error) {- lk := squirrel.ILike{}+ lk := squirrel.Like{}for f, v := range mapFields(ct) {lk[f] = fmt.Sprintf("%%%s%%", v)}@@ -113,7 +113,7 @@ func (ct Contains) MarshalJSON() ([]byte, error) {type NotContains map[string]interface{}func (nct NotContains) ToSql() (sql string, args []interface{}, err error) {- lk := squirrel.NotILike{}+ lk := squirrel.NotLike{}for f, v := range mapFields(nct) {lk[f] = fmt.Sprintf("%%%s%%", v)}@@ -127,7 +127,7 @@ func (nct NotContains) MarshalJSON() ([]byte, error) {type StartsWith map[string]interface{}func (sw StartsWith) ToSql() (sql string, args []interface{}, err error) {- lk := squirrel.ILike{}+ lk := squirrel.Like{}for f, v := range mapFields(sw) {lk[f] = fmt.Sprintf("%s%%", v)}@@ -141,7 +141,7 @@ func (sw StartsWith) MarshalJSON() ([]byte, error) {type EndsWith map[string]interface{}func (sw EndsWith) ToSql() (sql string, args []interface{}, err error) {- lk := squirrel.ILike{}+ lk := squirrel.Like{}for f, v := range mapFields(sw) {lk[f] = fmt.Sprintf("%%%s", v)}diff --git a/model/criteria/operators_test.go b/model/criteria/operators_test.goindex 886a6ac5b..5b5d405d7 100644--- a/model/criteria/operators_test.go+++ b/model/criteria/operators_test.go@@ -25,10 +25,10 @@ var _ = Describe("Operators", func() {Entry("isNot", IsNot{"title": "Low Rider"}, "media_file.title <> ?", "Low Rider"),Entry("gt", Gt{"playCount": 10}, "annotation.play_count > ?", 10),Entry("lt", Lt{"playCount": 10}, "annotation.play_count < ?", 10),- Entry("contains", Contains{"title": "Low Rider"}, "media_file.title ILIKE ?", "%Low Rider%"),- Entry("notContains", NotContains{"title": "Low Rider"}, "media_file.title NOT ILIKE ?", "%Low Rider%"),- Entry("startsWith", StartsWith{"title": "Low Rider"}, "media_file.title ILIKE ?", "Low Rider%"),- Entry("endsWith", EndsWith{"title": "Low Rider"}, "media_file.title ILIKE ?", "%Low Rider"),+ Entry("contains", Contains{"title": "Low Rider"}, "media_file.title LIKE ?", "%Low Rider%"),+ Entry("notContains", NotContains{"title": "Low Rider"}, "media_file.title NOT LIKE ?", "%Low Rider%"),+ Entry("startsWith", StartsWith{"title": "Low Rider"}, "media_file.title LIKE ?", "Low Rider%"),+ Entry("endsWith", EndsWith{"title": "Low Rider"}, "media_file.title LIKE ?", "%Low Rider"),Entry("inTheRange [number]", InTheRange{"year": []int{1980, 1990}}, "(media_file.year >= ? AND media_file.year <= ?)", 1980, 1990),Entry("inTheRange [date]", InTheRange{"lastPlayed": []Time{rangeStart, rangeEnd}}, "(annotation.play_date >= ? AND annotation.play_date <= ?)", rangeStart, rangeEnd),Entry("before", Before{"lastPlayed": rangeStart}, "annotation.play_date < ?", rangeStart),diff --git a/persistence/playlist_repository.go b/persistence/playlist_repository.goindex 2793cb8c9..795b7a5a6 100644--- a/persistence/playlist_repository.go+++ b/persistence/playlist_repository.go@@ -206,7 +206,9 @@ func (r *playlistRepository) refreshSmartPlaylist(pls *model.Playlist) bool {From("media_file").LeftJoin("annotation on (" +"annotation.item_id = media_file.id" +" AND annotation.item_type = 'media_file'" +- " AND annotation.user_id = '" + userId(r.ctx) + "')")+ " AND annotation.user_id = '" + userId(r.ctx) + "')").+ LeftJoin("media_file_genres ag on media_file.id = ag.media_file_id").+ LeftJoin("genre on ag.genre_id = genre.id").GroupBy("media_file.id")sql = r.addCriteria(sql, rules)insSql := Insert("playlist_tracks").Columns("id", "playlist_id", "media_file_id").Select(sql)c, err := r.executeSQL(insSql)