From 5dcc954072ca0a27107ed3fdc6806986f61df7d0 Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Thu, 6 Jun 2024 10:44:43 +0000 Subject: [feature] do not uncache status / emoji media if attached status is bookmarked (#2956) * do not uncache status / emoji media if attached status is bookmarked * add status bookmark and bookmark IDs caches * update status bookmark tests * move IsStatusBookmarkedBy() to StatusBookmark{} interface, rely on cache * fix envparsing.sh test --- internal/cleaner/emoji.go | 14 +++++++++++--- internal/cleaner/media.go | 22 ++++++++++++++++------ 2 files changed, 27 insertions(+), 9 deletions(-) (limited to 'internal/cleaner') diff --git a/internal/cleaner/emoji.go b/internal/cleaner/emoji.go index 62ed0f012..6cf194e40 100644 --- a/internal/cleaner/emoji.go +++ b/internal/cleaner/emoji.go @@ -32,9 +32,7 @@ import ( // Emoji encompasses a set of // emoji cleanup / admin utils. -type Emoji struct { - *Cleaner -} +type Emoji struct{ *Cleaner } // All will execute all cleaner.Emoji utilities synchronously, including output logging. // Context will be checked for `gtscontext.DryRun()` in order to actually perform the action. @@ -381,10 +379,20 @@ func (e *Emoji) uncacheRemote(ctx context.Context, after time.Time, emoji *gtsmo } for _, status := range statuses { + // Check if recently used status. if status.FetchedAt.After(after) { l.Debug("skipping due to recently fetched status") return false, nil } + + // Check whether status is bookmarked by active accounts. + bookmarked, err := e.state.DB.IsStatusBookmarked(ctx, status.ID) + if err != nil { + return false, err + } else if bookmarked { + l.Debug("skipping due to bookmarked status") + return false, nil + } } // This emoji is too old, uncache it. diff --git a/internal/cleaner/media.go b/internal/cleaner/media.go index 185c64fb9..bf4a08699 100644 --- a/internal/cleaner/media.go +++ b/internal/cleaner/media.go @@ -35,9 +35,7 @@ import ( // Media encompasses a set of // media cleanup / admin utils. -type Media struct { - *Cleaner -} +type Media struct{ *Cleaner } // All will execute all cleaner.Media utilities synchronously, including output logging. // Context will be checked for `gtscontext.DryRun()` in order to actually perform the action. @@ -475,9 +473,21 @@ func (m *Media) uncacheRemote(ctx context.Context, after time.Time, media *gtsmo return false, nil } - if status != nil && status.FetchedAt.After(after) { - l.Debug("skipping due to recently fetched status") - return false, nil + if status != nil { + // Check if recently used status. + if status.FetchedAt.After(after) { + l.Debug("skipping due to recently fetched status") + return false, nil + } + + // Check whether status is bookmarked by active accounts. + bookmarked, err := m.state.DB.IsStatusBookmarked(ctx, status.ID) + if err != nil { + return false, err + } else if bookmarked { + l.Debug("skipping due to bookmarked status") + return false, nil + } } } -- cgit v1.3