Fix giant lists

This commit is contained in:
bel
2019-12-27 20:04:00 -07:00
parent 6f7ff06e3f
commit 37408af647
3 changed files with 42 additions and 2 deletions

View File

@@ -7,6 +7,7 @@ import (
"net/http"
"regexp"
"sort"
"strconv"
"time"
"github.com/mmcdole/gofeed"
@@ -125,7 +126,7 @@ func (f *Feed) Items(limit int) ([]*Item, error) {
}
func (f *Feed) List(limit int) ([]string, error) {
keys, err := config.Values().DB.List([]string{nsItems, f.Key})
keys, err := config.Values().DB.List([]string{nsItems, f.Key}, " ", "}}}}}", strconv.Itoa(limit), "-")
if err != nil {
return nil, err
}

View File

@@ -177,3 +177,37 @@ func TestRSSFeedPull(t *testing.T) {
t.Fatal(i)
}
}
func TestRSSFeedListLimitedDescending(t *testing.T) {
initRSSFeed()
s := mockRSS()
defer s.Close()
f := newFeed("key")
f.TitleFilter = "50."
f.ContentFilter = "b"
f.Tags = []string{"c"}
f.URL = s.URL
log.SetOutput(bytes.NewBuffer(nil))
defer log.SetOutput(os.Stderr)
if err := f.Pull(); err != nil {
t.Fatal(err)
}
log.SetOutput(os.Stderr)
itemKeys, err := f.List(5)
if err != nil {
t.Fatal(err)
}
if len(itemKeys) != 5 {
t.Fatal(len(itemKeys))
}
for i := range itemKeys {
if i > 0 && itemKeys[i] > itemKeys[i-1] {
t.Error(itemKeys[i], ">", itemKeys[i-1])
}
}
}