From 947353610c993d0752c316f432bd481f2c4dc64d Mon Sep 17 00:00:00 2001 From: Deluan Date: Wed, 20 Oct 2021 09:14:27 -0400 Subject: [PATCH] Include never played songs in the "not in the last" operator --- persistence/sql_smartplaylist.go | 5 ++++- persistence/sql_smartplaylist_test.go | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/persistence/sql_smartplaylist.go b/persistence/sql_smartplaylist.go index a5bb4dad4..e0f150bcf 100644 --- a/persistence/sql_smartplaylist.go +++ b/persistence/sql_smartplaylist.go @@ -183,7 +183,10 @@ func (r dateRule) inTheLast(invert bool) (Sqlizer, error) { } period := time.Now().Add(time.Duration(-24*v) * time.Hour) if invert { - return Lt{r.Field: period}, nil + return Or{ + Lt{r.Field: period}, + Eq{r.Field: nil}, + }, nil } return Gt{r.Field: period}, nil } diff --git a/persistence/sql_smartplaylist_test.go b/persistence/sql_smartplaylist_test.go index ca0dbc922..3c181cce4 100644 --- a/persistence/sql_smartplaylist_test.go +++ b/persistence/sql_smartplaylist_test.go @@ -135,7 +135,7 @@ var _ = Describe("smartPlaylist", func() { Expect(args).To(ConsistOf(BeTemporally("~", expectedValue, delta))) }, Entry("in the last", "in the last", "lastPlayed > ?", date.Add(-90*24*time.Hour)), - Entry("not in the last", "not in the last", "lastPlayed < ?", date.Add(-90*24*time.Hour)), + Entry("not in the last", "not in the last", "(lastPlayed < ? OR lastPlayed IS NULL)", date.Add(-90*24*time.Hour)), ) It("accepts string as the 'in the last' operator value", func() {