diff --git a/src/server/logic/feed_follower.go b/src/server/logic/feed_follower.go index 02205b4..c16a467 100644 --- a/src/server/logic/feed_follower.go +++ b/src/server/logic/feed_follower.go @@ -2,10 +2,6 @@ package logic import ( "fmt" - "github.com/PuerkitoBio/goquery" - "github.com/microcosm-cc/bluemonday" - "github.com/mmcdole/gofeed" - "github.com/spaolacci/murmur3" "html" "math/rand" "net/http" @@ -18,6 +14,11 @@ import ( "strings" "sync" "time" + + "github.com/PuerkitoBio/goquery" + "github.com/microcosm-cc/bluemonday" + "github.com/mmcdole/gofeed" + "github.com/spaolacci/murmur3" ) //go:generate mockgen --build_flags=--mod=mod -destination ../test/mocks/mock_feed_follower.go -package mocks rss_parrot/logic IFeedFollower @@ -303,9 +304,17 @@ func (ff *feedFollower) updateAccountPosts( // Deal with feed items newer than our last seen // This goes from older to newer keepers, newLastUpdated := getSortedPosts(feed.Items, lastKnownFeedUpdated) + + // We still send toots from before the account was created, + // but limit their number to prevent sending a crazy number of toots. + oldTootsToSend := 5 + if !tootNew && len(keepers) > oldTootsToSend { + keepers = keepers[len(keepers)-oldTootsToSend:] + } + for _, k := range keepers { fixPodcastLink(k.itm) - if err = ff.storePostIfNew(accountId, accountHandle, k.postTime, k.itm, tootNew); err != nil { + if err = ff.storePostIfNew(accountId, accountHandle, k.postTime, k.itm); err != nil { return } } @@ -420,7 +429,6 @@ func (ff *feedFollower) storePostIfNew( accountHandle string, postTime time.Time, itm *gofeed.Item, - tootNew bool, ) (err error) { var isNew bool plainTitle := stripHtml(itm.Title) @@ -437,14 +445,14 @@ func (ff *feedFollower) storePostIfNew( } if isNew { ff.metrics.NewPostSaved() - if err = ff.createToot(accountId, accountHandle, itm, tootNew); err != nil { + if err = ff.createToot(accountId, accountHandle, itm); err != nil { return } } return } -func (ff *feedFollower) createToot(accountId int, accountHandle string, itm *gofeed.Item, sendToot bool) error { +func (ff *feedFollower) createToot(accountId int, accountHandle string, itm *gofeed.Item) error { prettyUrl := itm.Link prettyUrl = strings.TrimPrefix(prettyUrl, "http://") prettyUrl = strings.TrimPrefix(prettyUrl, "https://") @@ -471,10 +479,8 @@ func (ff *feedFollower) createToot(accountId int, accountHandle string, itm *gof if err != nil { return err } - if sendToot { - if err = ff.messenger.EnqueueBroadcast(accountHandle, statusId, tootedAt, content); err != nil { - return err - } + if err = ff.messenger.EnqueueBroadcast(accountHandle, statusId, tootedAt, content); err != nil { + return err } return nil }