[chore] tidy + test timelines a bit better (#1865)

* [chore] tidy + test timelines a bit better

* thanks linter
This commit is contained in:
tobi 2023-06-04 18:55:30 +02:00 committed by GitHub
commit 97bc2e713a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 685 additions and 479 deletions

View file

@ -19,7 +19,6 @@ package timeline
import (
"context"
"fmt"
"sync"
"time"
@ -76,6 +75,9 @@ type Manager interface {
// WipeStatusesFromAccountID removes all items by the given accountID from the given timeline.
WipeItemsFromAccountID(ctx context.Context, timelineID string, accountID string) error
// Prune manually triggers a prune operation for the given timelineID.
Prune(ctx context.Context, timelineID string, desiredPreparedItemsLength int, desiredIndexedItemsLength int) (int, error)
// Start starts hourly cleanup jobs for this timeline manager.
Start() error
@ -191,7 +193,7 @@ func (m *manager) WipeItemFromAllTimelines(ctx context.Context, itemID string) e
})
if len(errors) > 0 {
return fmt.Errorf("WipeItemFromAllTimelines: one or more errors wiping status %s: %w", itemID, errors.Combine())
return gtserror.Newf("one or more errors wiping status %s: %w", itemID, errors.Combine())
}
return nil
@ -202,6 +204,10 @@ func (m *manager) WipeItemsFromAccountID(ctx context.Context, timelineID string,
return err
}
func (m *manager) Prune(ctx context.Context, timelineID string, desiredPreparedItemsLength int, desiredIndexedItemsLength int) (int, error) {
return m.getOrCreateTimeline(ctx, timelineID).Prune(desiredPreparedItemsLength, desiredIndexedItemsLength), nil
}
// getOrCreateTimeline returns a timeline with the given id,
// creating a new timeline with that id if necessary.
func (m *manager) getOrCreateTimeline(ctx context.Context, timelineID string) Timeline {