From b9d4e7e1d9c15d9b78a2690eecd03751ea865983 Mon Sep 17 00:00:00 2001 From: Yoo Chung Date: Thu, 21 Nov 2024 19:40:49 +0000 Subject: [PATCH 1/2] Send a limited number of old toots for new feeds. --- src/server/logic/feed_follower.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/server/logic/feed_follower.go b/src/server/logic/feed_follower.go index 02205b4..c2bde62 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, true); err != nil { return } } From c40865ecb5b7e5fdcfef21dceb80e2bb54d17435 Mon Sep 17 00:00:00 2001 From: Yoo Chung Date: Thu, 21 Nov 2024 19:44:48 +0000 Subject: [PATCH 2/2] Delete parameters that no longer accept more than one value. --- src/server/logic/feed_follower.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/server/logic/feed_follower.go b/src/server/logic/feed_follower.go index c2bde62..c16a467 100644 --- a/src/server/logic/feed_follower.go +++ b/src/server/logic/feed_follower.go @@ -314,7 +314,7 @@ func (ff *feedFollower) updateAccountPosts( for _, k := range keepers { fixPodcastLink(k.itm) - if err = ff.storePostIfNew(accountId, accountHandle, k.postTime, k.itm, true); err != nil { + if err = ff.storePostIfNew(accountId, accountHandle, k.postTime, k.itm); err != nil { return } } @@ -429,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) @@ -446,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://") @@ -480,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 }