From 8fc01db2755867ee0ced8e7c8ebf3009285c76a6 Mon Sep 17 00:00:00 2001 From: nkanaev Date: Sun, 10 May 2026 22:18:37 +0100 Subject: [PATCH] remove filter in CountItems --- src/server/fever.go | 2 +- src/storage/item.go | 11 ++--------- src/storage/item_test.go | 9 ++++++--- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/server/fever.go b/src/server/fever.go index 3816ed3..f4996de 100644 --- a/src/server/fever.go +++ b/src/server/fever.go @@ -278,7 +278,7 @@ func (s *Server) feverItemsHandler(c *router.Context) { } } - totalItems := s.db.CountItems(storage.ItemFilter{}) + totalItems := s.db.CountItems() writeFeverJSON(c, map[string]any{ "items": feverItems, diff --git a/src/storage/item.go b/src/storage/item.go index 1e578bb..282e413 100644 --- a/src/storage/item.go +++ b/src/storage/item.go @@ -243,16 +243,9 @@ func listQueryPredicate(filter ItemFilter, newestFirst bool) (string, []any) { return predicate, args } -func (s *Storage) CountItems(filter ItemFilter) int { - predicate, args := listQueryPredicate(filter, false) - +func (s *Storage) CountItems() int { var count int - query := fmt.Sprintf(` - select count(*) - from items i - where %s - `, predicate) - err := s.db.QueryRow(query, args...).Scan(&count) + err := s.db.QueryRow(`select count(*) from items`).Scan(&count) if err != nil { log.Print(err) return 0 diff --git a/src/storage/item_test.go b/src/storage/item_test.go index 72bf864..3f3b8b7 100644 --- a/src/storage/item_test.go +++ b/src/storage/item_test.go @@ -338,7 +338,8 @@ func TestDeleteOldItems(t *testing.T) { db.db.Exec(`update items set last_arrived = :la where guid != "99"`, sql.Named("la", now.Add(-time.Hour*24*100))) db.DeleteOldItems() - have := db.CountItems(ItemFilter{FeedID: &feed.Id}) + var have int + db.db.QueryRow("select count(*) from items where feed_id = ?", feed.Id).Scan(&have) if have != 50 { t.Errorf("expected 50 items, have %d", have) } @@ -359,7 +360,8 @@ func TestDeleteOldItems(t *testing.T) { db.db.Exec(`update items set last_arrived = :la where guid != "99"`, sql.Named("la", now.Add(-time.Hour*24*80))) db.DeleteOldItems() - have := db.CountItems(ItemFilter{FeedID: &feed.Id}) + var have int + db.db.QueryRow("select count(*) from items where feed_id = ?", feed.Id).Scan(&have) if have != 100 { t.Errorf("expected 100 items, have %d", have) } @@ -381,7 +383,8 @@ func TestDeleteOldItems(t *testing.T) { db.db.Exec(`update items set status = :s where cast(guid as integer) < 10`, sql.Named("s", starred)) db.DeleteOldItems() - have := db.CountItems(ItemFilter{FeedID: &feed.Id}) + var have int + db.db.QueryRow("select count(*) from items where feed_id = ?", feed.Id).Scan(&have) // 50 (limit) + 10 (starred) = 60 items should remain. if have != 60 { t.Errorf("expected 60 items, have %d", have)