summaryrefslogtreecommitdiff
path: root/internal/timeline/manager.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-06-11 11:18:44 +0200
committerLibravatar GitHub <noreply@github.com>2023-06-11 10:18:44 +0100
commit5e2897e35cd2bea889fa37a2a857f4dcc076dafc (patch)
treeb1ac6203ffa20f5fff1c460fed942854a6e5c6bd /internal/timeline/manager.go
parent[docs] Revamp the installation guide (#1877) (diff)
downloadgotosocial-5e2897e35cd2bea889fa37a2a857f4dcc076dafc.tar.xz
[bugfix] Invalidate timeline entries for status when stats change (#1879)
Diffstat (limited to 'internal/timeline/manager.go')
-rw-r--r--internal/timeline/manager.go35
1 files changed, 34 insertions, 1 deletions
diff --git a/internal/timeline/manager.go b/internal/timeline/manager.go
index 95a40aca1..a701756bb 100644
--- a/internal/timeline/manager.go
+++ b/internal/timeline/manager.go
@@ -75,6 +75,14 @@ type Manager interface {
// WipeStatusesFromAccountID removes all items by the given accountID from the given timeline.
WipeItemsFromAccountID(ctx context.Context, timelineID string, accountID string) error
+ // UnprepareItem unprepares/uncaches the prepared version fo the given itemID from the given timelineID.
+ // Use this for cache invalidation when the prepared representation of an item has changed.
+ UnprepareItem(ctx context.Context, timelineID string, itemID string) error
+
+ // UnprepareItemFromAllTimelines unprepares/uncaches the prepared version of the given itemID from all timelines.
+ // Use this for cache invalidation when the prepared representation of an item has changed.
+ UnprepareItemFromAllTimelines(ctx context.Context, itemID string) error
+
// Prune manually triggers a prune operation for the given timelineID.
Prune(ctx context.Context, timelineID string, desiredPreparedItemsLength int, desiredIndexedItemsLength int) (int, error)
@@ -193,7 +201,7 @@ func (m *manager) WipeItemFromAllTimelines(ctx context.Context, itemID string) e
})
if len(errors) > 0 {
- return gtserror.Newf("one or more errors wiping status %s: %w", itemID, errors.Combine())
+ return gtserror.Newf("error(s) wiping status %s: %w", itemID, errors.Combine())
}
return nil
@@ -204,6 +212,31 @@ func (m *manager) WipeItemsFromAccountID(ctx context.Context, timelineID string,
return err
}
+func (m *manager) UnprepareItemFromAllTimelines(ctx context.Context, itemID string) error {
+ errors := gtserror.MultiError{}
+
+ // Work through all timelines held by this
+ // manager, and call Unprepare for each.
+ m.timelines.Range(func(_ any, v any) bool {
+ // nolint:forcetypeassert
+ if err := v.(Timeline).Unprepare(ctx, itemID); err != nil {
+ errors.Append(err)
+ }
+
+ return true // always continue range
+ })
+
+ if len(errors) > 0 {
+ return gtserror.Newf("error(s) unpreparing status %s: %w", itemID, errors.Combine())
+ }
+
+ return nil
+}
+
+func (m *manager) UnprepareItem(ctx context.Context, timelineID string, itemID string) error {
+ return m.getOrCreateTimeline(ctx, timelineID).Unprepare(ctx, itemID)
+}
+
func (m *manager) Prune(ctx context.Context, timelineID string, desiredPreparedItemsLength int, desiredIndexedItemsLength int) (int, error) {
return m.getOrCreateTimeline(ctx, timelineID).Prune(desiredPreparedItemsLength, desiredIndexedItemsLength), nil
}