From 8125275936030b84355aced06d7e0721b6188d63 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Fri, 7 Feb 2025 06:53:42 -0800 Subject: [PATCH] Fix tests broken by tts --- core/items.go | 8 +++++--- core/items_test.go | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/core/items.go b/core/items.go index c99bfe1..ba1b40f 100644 --- a/core/items.go +++ b/core/items.go @@ -193,13 +193,15 @@ func GetItem(db DB, source string, id string) (Item, error) { } func GetAllActiveItems(db DB) ([]Item, error) { + now := int(time.Now().Unix()) // TODO pass this value in return getItems(db, ` select source, id, created, active, title, author, body, link, time, ttl, ttd, tts, json(action) from items where active <> 0 + and (tts = 0 or created + tts < ?) order by case when time = 0 then created else time end, id - `) + `, now) } func GetAllItems(db DB) ([]Item, error) { @@ -220,7 +222,7 @@ func GetActiveItemsForSource(db DB, source string) ([]Item, error) { where source = ? and active <> 0 - and created + tts < ? + and (tts = 0 or created + tts < ?) order by case when time = 0 then created else time end, id `, source, now) } @@ -246,7 +248,7 @@ func GetActiveItemsForChannel(db DB, channel string) ([]Item, error) { where c.name = ? and i.active <> 0 - and i.created + i.tts < ? + and (i.tts = 0 or i.created + i.tts < ?) order by case when i.time = 0 then i.created else i.time end, i.id `, channel, now) } diff --git a/core/items_test.go b/core/items_test.go index f0702c0..9e1128b 100644 --- a/core/items_test.go +++ b/core/items_test.go @@ -33,7 +33,7 @@ func TestAddItem(t *testing.T) { if err := AddItems(db, []Item{ {Source: "test", Id: "one", Active: true}, - {"test", "two", 0, true, "title", "author", "body", "link", 123456, 1, 2, 3, nil}, + {"test", "two", 0, true, "title", "author", "body", "link", 123456, 1, 2, -3, nil}, }); err != nil { t.Fatalf("failed to add items: %v", err) }