mirror of
https://github.com/nkanaev/yarr.git
synced 2026-05-13 12:43:21 +00:00
remove filter in CountItems
This commit is contained in:
@@ -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{
|
writeFeverJSON(c, map[string]any{
|
||||||
"items": feverItems,
|
"items": feverItems,
|
||||||
|
|||||||
@@ -243,16 +243,9 @@ func listQueryPredicate(filter ItemFilter, newestFirst bool) (string, []any) {
|
|||||||
return predicate, args
|
return predicate, args
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) CountItems(filter ItemFilter) int {
|
func (s *Storage) CountItems() int {
|
||||||
predicate, args := listQueryPredicate(filter, false)
|
|
||||||
|
|
||||||
var count int
|
var count int
|
||||||
query := fmt.Sprintf(`
|
err := s.db.QueryRow(`select count(*) from items`).Scan(&count)
|
||||||
select count(*)
|
|
||||||
from items i
|
|
||||||
where %s
|
|
||||||
`, predicate)
|
|
||||||
err := s.db.QueryRow(query, args...).Scan(&count)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
@@ -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.db.Exec(`update items set last_arrived = :la where guid != "99"`, sql.Named("la", now.Add(-time.Hour*24*100)))
|
||||||
|
|
||||||
db.DeleteOldItems()
|
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 {
|
if have != 50 {
|
||||||
t.Errorf("expected 50 items, have %d", have)
|
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.db.Exec(`update items set last_arrived = :la where guid != "99"`, sql.Named("la", now.Add(-time.Hour*24*80)))
|
||||||
|
|
||||||
db.DeleteOldItems()
|
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 {
|
if have != 100 {
|
||||||
t.Errorf("expected 100 items, have %d", have)
|
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.db.Exec(`update items set status = :s where cast(guid as integer) < 10`, sql.Named("s", starred))
|
||||||
|
|
||||||
db.DeleteOldItems()
|
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.
|
// 50 (limit) + 10 (starred) = 60 items should remain.
|
||||||
if have != 60 {
|
if have != 60 {
|
||||||
t.Errorf("expected 60 items, have %d", have)
|
t.Errorf("expected 60 items, have %d", have)
|
||||||
|
|||||||
Reference in New Issue
Block a user