small pixel drawing of a pufferfish vore

optimize HasFeed to speed up submission
Jes Olson j3s@c3f.net
Sun, 27 Aug 2023 20:38:57 -0500
commit

105d809498e2d64af67d04a0ce3baa515396fb7d

parent

27d786d8e1da746eaeeb99091a6de03044bea000

3 files changed, 29 insertions(+), 5 deletions(-)

jump to
M reaper/reaper.goreaper/reaper.go

@@ -93,13 +93,11 @@ log.Printf("[err] reaper: could not set feed fetch error '%s'\n", err)

} } -// Have checks whether a given url is represented +// HasFeed checks whether a given url is represented // in the reaper cache. func (r *Reaper) HasFeed(url string) bool { - for _, f := range r.feeds { - if f.UpdateURL == url { - return true - } + if _, ok := r.feeds[url]; ok { + return true } return false }
A reaper/reaper_test.go

@@ -0,0 +1,26 @@

+package reaper + +import ( + "testing" + + "git.j3s.sh/vore/rss" + "git.j3s.sh/vore/sqlite" +) + +func TestHasFeed(t *testing.T) { + db := sqlite.New("go_test.db") + r := New(db) + f1 := rss.Feed{UpdateURL: "something"} + f2 := rss.Feed{UpdateURL: "strange"} + r.addFeed(&f1) + r.addFeed(&f2) + if r.HasFeed("banana") == true { + t.Fatal("reaper should not have a banana") + } + if r.HasFeed("something") == false { + t.Fatal("reaper should have something") + } + if r.HasFeed("strange") == false { + t.Fatal("reaper should have strange") + } +}