mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 07:22:24 -05:00
[feature] Add List functionality (#1802)
* start working on lists * further list work * test list db functions nicely * more work on lists * peepoopeepoo * poke * start list timeline func * we're getting there lads * couldn't be me working on stuff... could it? * hook up handlers * fiddling * weeee * woah * screaming, pissing * fix streaming being a whiny baby * lint, small test fix, swagger * tidying up, testing * fucked! by the linter * move timelines to state like a boss * add timeline start to tests using state * invalidate lists
This commit is contained in:
parent
282be6f26d
commit
f5c004d67d
123 changed files with 5654 additions and 970 deletions
|
|
@ -39,7 +39,7 @@ func (t *timeline) LastGot() time.Time {
|
|||
func (t *timeline) Get(ctx context.Context, amount int, maxID string, sinceID string, minID string, prepareNext bool) ([]Preparable, error) {
|
||||
l := log.WithContext(ctx).
|
||||
WithFields(kv.Fields{
|
||||
{"accountID", t.accountID},
|
||||
{"accountID", t.timelineID},
|
||||
{"amount", amount},
|
||||
{"maxID", maxID},
|
||||
{"sinceID", sinceID},
|
||||
|
|
@ -244,7 +244,7 @@ func (t *timeline) getXBetweenIDs(ctx context.Context, amount int, behindID stri
|
|||
if entry.prepared == nil {
|
||||
// Whoops, this entry isn't prepared yet; some
|
||||
// race condition? That's OK, we can do it now.
|
||||
prepared, err := t.prepareFunction(ctx, t.accountID, entry.itemID)
|
||||
prepared, err := t.prepareFunction(ctx, t.timelineID, entry.itemID)
|
||||
if err != nil {
|
||||
if errors.Is(err, db.ErrNoEntries) {
|
||||
// ErrNoEntries means something has been deleted,
|
||||
|
|
@ -338,7 +338,7 @@ func (t *timeline) getXBetweenIDs(ctx context.Context, amount int, behindID stri
|
|||
if entry.prepared == nil {
|
||||
// Whoops, this entry isn't prepared yet; some
|
||||
// race condition? That's OK, we can do it now.
|
||||
prepared, err := t.prepareFunction(ctx, t.accountID, entry.itemID)
|
||||
prepared, err := t.prepareFunction(ctx, t.timelineID, entry.itemID)
|
||||
if err != nil {
|
||||
if errors.Is(err, db.ErrNoEntries) {
|
||||
// ErrNoEntries means something has been deleted,
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import (
|
|||
"github.com/stretchr/testify/suite"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/id"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/processing"
|
||||
tlprocessor "github.com/superseriousbusiness/gotosocial/internal/processing/timeline"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/timeline"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/visibility"
|
||||
"github.com/superseriousbusiness/gotosocial/testrig"
|
||||
|
|
@ -58,10 +58,10 @@ func (suite *GetTestSuite) SetupTest() {
|
|||
tl := timeline.NewTimeline(
|
||||
context.Background(),
|
||||
suite.testAccounts["local_account_1"].ID,
|
||||
processing.StatusGrabFunction(suite.db),
|
||||
processing.StatusFilterFunction(suite.db, suite.filter),
|
||||
processing.StatusPrepareFunction(suite.db, suite.tc),
|
||||
processing.StatusSkipInsertFunction(),
|
||||
tlprocessor.HomeTimelineGrab(&suite.state),
|
||||
tlprocessor.HomeTimelineFilter(&suite.state, suite.filter),
|
||||
tlprocessor.HomeTimelineStatusPrepare(&suite.state, suite.tc),
|
||||
tlprocessor.SkipInsert(),
|
||||
)
|
||||
|
||||
// Put testrig statuses in a determinate order
|
||||
|
|
@ -134,10 +134,10 @@ func (suite *GetTestSuite) TestGetNewTimelinePageDown() {
|
|||
tl := timeline.NewTimeline(
|
||||
context.Background(),
|
||||
suite.testAccounts["local_account_1"].ID,
|
||||
processing.StatusGrabFunction(suite.db),
|
||||
processing.StatusFilterFunction(suite.db, suite.filter),
|
||||
processing.StatusPrepareFunction(suite.db, suite.tc),
|
||||
processing.StatusSkipInsertFunction(),
|
||||
tlprocessor.HomeTimelineGrab(&suite.state),
|
||||
tlprocessor.HomeTimelineFilter(&suite.state, suite.filter),
|
||||
tlprocessor.HomeTimelineStatusPrepare(&suite.state, suite.tc),
|
||||
tlprocessor.SkipInsert(),
|
||||
)
|
||||
|
||||
// Get 5 from the top.
|
||||
|
|
@ -163,10 +163,10 @@ func (suite *GetTestSuite) TestGetNewTimelinePageUp() {
|
|||
tl := timeline.NewTimeline(
|
||||
context.Background(),
|
||||
suite.testAccounts["local_account_1"].ID,
|
||||
processing.StatusGrabFunction(suite.db),
|
||||
processing.StatusFilterFunction(suite.db, suite.filter),
|
||||
processing.StatusPrepareFunction(suite.db, suite.tc),
|
||||
processing.StatusSkipInsertFunction(),
|
||||
tlprocessor.HomeTimelineGrab(&suite.state),
|
||||
tlprocessor.HomeTimelineFilter(&suite.state, suite.filter),
|
||||
tlprocessor.HomeTimelineStatusPrepare(&suite.state, suite.tc),
|
||||
tlprocessor.SkipInsert(),
|
||||
)
|
||||
|
||||
// Get 5 from the back.
|
||||
|
|
@ -192,10 +192,10 @@ func (suite *GetTestSuite) TestGetNewTimelineMoreThanPossible() {
|
|||
tl := timeline.NewTimeline(
|
||||
context.Background(),
|
||||
suite.testAccounts["local_account_1"].ID,
|
||||
processing.StatusGrabFunction(suite.db),
|
||||
processing.StatusFilterFunction(suite.db, suite.filter),
|
||||
processing.StatusPrepareFunction(suite.db, suite.tc),
|
||||
processing.StatusSkipInsertFunction(),
|
||||
tlprocessor.HomeTimelineGrab(&suite.state),
|
||||
tlprocessor.HomeTimelineFilter(&suite.state, suite.filter),
|
||||
tlprocessor.HomeTimelineStatusPrepare(&suite.state, suite.tc),
|
||||
tlprocessor.SkipInsert(),
|
||||
)
|
||||
|
||||
// Get 100 from the top.
|
||||
|
|
@ -213,10 +213,10 @@ func (suite *GetTestSuite) TestGetNewTimelineMoreThanPossiblePageUp() {
|
|||
tl := timeline.NewTimeline(
|
||||
context.Background(),
|
||||
suite.testAccounts["local_account_1"].ID,
|
||||
processing.StatusGrabFunction(suite.db),
|
||||
processing.StatusFilterFunction(suite.db, suite.filter),
|
||||
processing.StatusPrepareFunction(suite.db, suite.tc),
|
||||
processing.StatusSkipInsertFunction(),
|
||||
tlprocessor.HomeTimelineGrab(&suite.state),
|
||||
tlprocessor.HomeTimelineFilter(&suite.state, suite.filter),
|
||||
tlprocessor.HomeTimelineStatusPrepare(&suite.state, suite.tc),
|
||||
tlprocessor.SkipInsert(),
|
||||
)
|
||||
|
||||
// Get 100 from the back.
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@ func (t *timeline) grab(ctx context.Context, amount int, behindID string, before
|
|||
|
||||
items, stop, err := t.grabFunction(
|
||||
ctx,
|
||||
t.accountID,
|
||||
t.timelineID,
|
||||
maxID,
|
||||
sinceID,
|
||||
minID,
|
||||
|
|
@ -205,7 +205,7 @@ func (t *timeline) grab(ctx context.Context, amount int, behindID string, before
|
|||
}
|
||||
|
||||
for _, item := range items {
|
||||
ok, err := t.filterFunction(ctx, t.accountID, item)
|
||||
ok, err := t.filterFunction(ctx, t.timelineID, item)
|
||||
if err != nil {
|
||||
if !errors.Is(err, db.ErrNoEntries) {
|
||||
// Real error here.
|
||||
|
|
@ -244,7 +244,7 @@ func (t *timeline) IndexAndPrepareOne(ctx context.Context, statusID string, boos
|
|||
return false, nil
|
||||
}
|
||||
|
||||
preparable, err := t.prepareFunction(ctx, t.accountID, statusID)
|
||||
preparable, err := t.prepareFunction(ctx, t.timelineID, statusID)
|
||||
if err != nil {
|
||||
return true, fmt.Errorf("IndexAndPrepareOne: error preparing: %w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/processing"
|
||||
tlprocessor "github.com/superseriousbusiness/gotosocial/internal/processing/timeline"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/timeline"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/visibility"
|
||||
"github.com/superseriousbusiness/gotosocial/testrig"
|
||||
|
|
@ -55,10 +55,10 @@ func (suite *IndexTestSuite) SetupTest() {
|
|||
suite.timeline = timeline.NewTimeline(
|
||||
context.Background(),
|
||||
suite.testAccounts["local_account_1"].ID,
|
||||
processing.StatusGrabFunction(suite.db),
|
||||
processing.StatusFilterFunction(suite.db, suite.filter),
|
||||
processing.StatusPrepareFunction(suite.db, suite.tc),
|
||||
processing.StatusSkipInsertFunction(),
|
||||
tlprocessor.HomeTimelineGrab(&suite.state),
|
||||
tlprocessor.HomeTimelineFilter(&suite.state, suite.filter),
|
||||
tlprocessor.HomeTimelineStatusPrepare(&suite.state, suite.tc),
|
||||
tlprocessor.SkipInsert(),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,10 +32,10 @@ const (
|
|||
pruneLengthPrepared = 50
|
||||
)
|
||||
|
||||
// Manager abstracts functions for creating timelines for multiple accounts, and adding, removing, and fetching entries from those timelines.
|
||||
// Manager abstracts functions for creating multiple timelines, and adding, removing, and fetching entries from those timelines.
|
||||
//
|
||||
// By the time a timelineable hits the manager interface, it should already have been filtered and it should be established that the item indeed
|
||||
// belongs in the timeline of the given account ID.
|
||||
// belongs in the given timeline.
|
||||
//
|
||||
// The manager makes a distinction between *indexed* items and *prepared* items.
|
||||
//
|
||||
|
|
@ -45,33 +45,36 @@ const (
|
|||
// Prepared items consist of the item's database ID, the time it was created, AND the apimodel representation of that item, for quick serialization.
|
||||
// Prepared items of course take up more memory than indexed items, so they should be regularly pruned if they're not being actively served.
|
||||
type Manager interface {
|
||||
// IngestOne takes one timelineable and indexes it into the timeline for the given account ID, and then immediately prepares it for serving.
|
||||
// IngestOne takes one timelineable and indexes it into the given timeline, and then immediately prepares it for serving.
|
||||
// This is useful in cases where we know the item will need to be shown at the top of a user's timeline immediately (eg., a new status is created).
|
||||
//
|
||||
// It should already be established before calling this function that the item actually belongs in the timeline!
|
||||
//
|
||||
// The returned bool indicates whether the item was actually put in the timeline. This could be false in cases where
|
||||
// a status is a boost, but a boost of the original status or the status itself already exists recently in the timeline.
|
||||
IngestOne(ctx context.Context, accountID string, item Timelineable) (bool, error)
|
||||
IngestOne(ctx context.Context, timelineID string, item Timelineable) (bool, error)
|
||||
|
||||
// GetTimeline returns limit n amount of prepared entries from the timeline of the given account ID, in descending chronological order.
|
||||
GetTimeline(ctx context.Context, accountID string, maxID string, sinceID string, minID string, limit int, local bool) ([]Preparable, error)
|
||||
// GetTimeline returns limit n amount of prepared entries from the given timeline, in descending chronological order.
|
||||
GetTimeline(ctx context.Context, timelineID string, maxID string, sinceID string, minID string, limit int, local bool) ([]Preparable, error)
|
||||
|
||||
// GetIndexedLength returns the amount of items that have been indexed for the given account ID.
|
||||
GetIndexedLength(ctx context.Context, accountID string) int
|
||||
GetIndexedLength(ctx context.Context, timelineID string) int
|
||||
|
||||
// GetOldestIndexedID returns the id ID for the oldest item that we have indexed for the given account.
|
||||
// GetOldestIndexedID returns the id ID for the oldest item that we have indexed for the given timeline.
|
||||
// Will be an empty string if nothing is (yet) indexed.
|
||||
GetOldestIndexedID(ctx context.Context, accountID string) string
|
||||
GetOldestIndexedID(ctx context.Context, timelineID string) string
|
||||
|
||||
// Remove removes one item from the timeline of the given timelineAccountID
|
||||
Remove(ctx context.Context, accountID string, itemID string) (int, error)
|
||||
// Remove removes one item from the given timeline.
|
||||
Remove(ctx context.Context, timelineID string, itemID string) (int, error)
|
||||
|
||||
// RemoveTimeline completely removes one timeline.
|
||||
RemoveTimeline(ctx context.Context, timelineID string) error
|
||||
|
||||
// WipeItemFromAllTimelines removes one item from the index and prepared items of all timelines
|
||||
WipeItemFromAllTimelines(ctx context.Context, itemID string) error
|
||||
|
||||
// WipeStatusesFromAccountID removes all items by the given accountID from the timelineAccountID's timelines.
|
||||
WipeItemsFromAccountID(ctx context.Context, timelineAccountID string, accountID string) error
|
||||
// WipeStatusesFromAccountID removes all items by the given accountID from the given timeline.
|
||||
WipeItemsFromAccountID(ctx context.Context, timelineID string, accountID string) error
|
||||
|
||||
// Start starts hourly cleanup jobs for this timeline manager.
|
||||
Start() error
|
||||
|
|
@ -83,7 +86,7 @@ type Manager interface {
|
|||
// NewManager returns a new timeline manager.
|
||||
func NewManager(grabFunction GrabFunction, filterFunction FilterFunction, prepareFunction PrepareFunction, skipInsertFunction SkipInsertFunction) Manager {
|
||||
return &manager{
|
||||
accountTimelines: sync.Map{},
|
||||
timelines: sync.Map{},
|
||||
grabFunction: grabFunction,
|
||||
filterFunction: filterFunction,
|
||||
prepareFunction: prepareFunction,
|
||||
|
|
@ -92,7 +95,7 @@ func NewManager(grabFunction GrabFunction, filterFunction FilterFunction, prepar
|
|||
}
|
||||
|
||||
type manager struct {
|
||||
accountTimelines sync.Map
|
||||
timelines sync.Map
|
||||
grabFunction GrabFunction
|
||||
filterFunction FilterFunction
|
||||
prepareFunction PrepareFunction
|
||||
|
|
@ -127,14 +130,14 @@ func (m *manager) Start() error {
|
|||
}
|
||||
|
||||
if amountPruned := timeline.Prune(pruneLengthPrepared, pruneLengthIndexed); amountPruned > 0 {
|
||||
log.WithField("accountID", timeline.AccountID()).Infof("pruned %d indexed and prepared items from timeline", amountPruned)
|
||||
log.WithField("accountID", timeline.TimelineID()).Infof("pruned %d indexed and prepared items from timeline", amountPruned)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// Execute the function for each timeline.
|
||||
m.accountTimelines.Range(f)
|
||||
m.timelines.Range(f)
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
@ -145,8 +148,8 @@ func (m *manager) Stop() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (m *manager) IngestOne(ctx context.Context, accountID string, item Timelineable) (bool, error) {
|
||||
return m.getOrCreateTimeline(ctx, accountID).IndexAndPrepareOne(
|
||||
func (m *manager) IngestOne(ctx context.Context, timelineID string, item Timelineable) (bool, error) {
|
||||
return m.getOrCreateTimeline(ctx, timelineID).IndexAndPrepareOne(
|
||||
ctx,
|
||||
item.GetID(),
|
||||
item.GetBoostOfID(),
|
||||
|
|
@ -155,27 +158,32 @@ func (m *manager) IngestOne(ctx context.Context, accountID string, item Timeline
|
|||
)
|
||||
}
|
||||
|
||||
func (m *manager) Remove(ctx context.Context, accountID string, itemID string) (int, error) {
|
||||
return m.getOrCreateTimeline(ctx, accountID).Remove(ctx, itemID)
|
||||
func (m *manager) Remove(ctx context.Context, timelineID string, itemID string) (int, error) {
|
||||
return m.getOrCreateTimeline(ctx, timelineID).Remove(ctx, itemID)
|
||||
}
|
||||
|
||||
func (m *manager) GetTimeline(ctx context.Context, accountID string, maxID string, sinceID string, minID string, limit int, local bool) ([]Preparable, error) {
|
||||
return m.getOrCreateTimeline(ctx, accountID).Get(ctx, limit, maxID, sinceID, minID, true)
|
||||
func (m *manager) RemoveTimeline(ctx context.Context, timelineID string) error {
|
||||
m.timelines.Delete(timelineID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *manager) GetIndexedLength(ctx context.Context, accountID string) int {
|
||||
return m.getOrCreateTimeline(ctx, accountID).Len()
|
||||
func (m *manager) GetTimeline(ctx context.Context, timelineID string, maxID string, sinceID string, minID string, limit int, local bool) ([]Preparable, error) {
|
||||
return m.getOrCreateTimeline(ctx, timelineID).Get(ctx, limit, maxID, sinceID, minID, true)
|
||||
}
|
||||
|
||||
func (m *manager) GetOldestIndexedID(ctx context.Context, accountID string) string {
|
||||
return m.getOrCreateTimeline(ctx, accountID).OldestIndexedItemID()
|
||||
func (m *manager) GetIndexedLength(ctx context.Context, timelineID string) int {
|
||||
return m.getOrCreateTimeline(ctx, timelineID).Len()
|
||||
}
|
||||
|
||||
func (m *manager) WipeItemFromAllTimelines(ctx context.Context, statusID string) error {
|
||||
func (m *manager) GetOldestIndexedID(ctx context.Context, timelineID string) string {
|
||||
return m.getOrCreateTimeline(ctx, timelineID).OldestIndexedItemID()
|
||||
}
|
||||
|
||||
func (m *manager) WipeItemFromAllTimelines(ctx context.Context, itemID string) error {
|
||||
errors := gtserror.MultiError{}
|
||||
|
||||
m.accountTimelines.Range(func(_ any, v any) bool {
|
||||
if _, err := v.(Timeline).Remove(ctx, statusID); err != nil {
|
||||
m.timelines.Range(func(_ any, v any) bool {
|
||||
if _, err := v.(Timeline).Remove(ctx, itemID); err != nil {
|
||||
errors.Append(err)
|
||||
}
|
||||
|
||||
|
|
@ -183,22 +191,21 @@ func (m *manager) WipeItemFromAllTimelines(ctx context.Context, statusID string)
|
|||
})
|
||||
|
||||
if len(errors) > 0 {
|
||||
return fmt.Errorf("WipeItemFromAllTimelines: one or more errors wiping status %s: %w", statusID, errors.Combine())
|
||||
return fmt.Errorf("WipeItemFromAllTimelines: one or more errors wiping status %s: %w", itemID, errors.Combine())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *manager) WipeItemsFromAccountID(ctx context.Context, timelineAccountID string, accountID string) error {
|
||||
_, err := m.getOrCreateTimeline(ctx, timelineAccountID).RemoveAllByOrBoosting(ctx, accountID)
|
||||
func (m *manager) WipeItemsFromAccountID(ctx context.Context, timelineID string, accountID string) error {
|
||||
_, err := m.getOrCreateTimeline(ctx, timelineID).RemoveAllByOrBoosting(ctx, accountID)
|
||||
return err
|
||||
}
|
||||
|
||||
// getOrCreateTimeline returns a timeline for the given
|
||||
// accountID. If a timeline does not yet exist in the
|
||||
// manager's sync.Map, it will be created and stored.
|
||||
func (m *manager) getOrCreateTimeline(ctx context.Context, accountID string) Timeline {
|
||||
i, ok := m.accountTimelines.Load(accountID)
|
||||
// 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 {
|
||||
i, ok := m.timelines.Load(timelineID)
|
||||
if ok {
|
||||
// Timeline already existed in sync.Map.
|
||||
return i.(Timeline) //nolint:forcetypeassert
|
||||
|
|
@ -206,8 +213,8 @@ func (m *manager) getOrCreateTimeline(ctx context.Context, accountID string) Tim
|
|||
|
||||
// Timeline did not yet exist in sync.Map.
|
||||
// Create + store it.
|
||||
timeline := NewTimeline(ctx, accountID, m.grabFunction, m.filterFunction, m.prepareFunction, m.skipInsertFunction)
|
||||
m.accountTimelines.Store(accountID, timeline)
|
||||
timeline := NewTimeline(ctx, timelineID, m.grabFunction, m.filterFunction, m.prepareFunction, m.skipInsertFunction)
|
||||
m.timelines.Store(timelineID, timeline)
|
||||
|
||||
return timeline
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/processing"
|
||||
tlprocessor "github.com/superseriousbusiness/gotosocial/internal/processing/timeline"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/timeline"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/visibility"
|
||||
"github.com/superseriousbusiness/gotosocial/testrig"
|
||||
|
|
@ -50,10 +50,10 @@ func (suite *ManagerTestSuite) SetupTest() {
|
|||
testrig.StandardDBSetup(suite.db, nil)
|
||||
|
||||
manager := timeline.NewManager(
|
||||
processing.StatusGrabFunction(suite.db),
|
||||
processing.StatusFilterFunction(suite.db, suite.filter),
|
||||
processing.StatusPrepareFunction(suite.db, suite.tc),
|
||||
processing.StatusSkipInsertFunction(),
|
||||
tlprocessor.HomeTimelineGrab(&suite.state),
|
||||
tlprocessor.HomeTimelineFilter(&suite.state, suite.filter),
|
||||
tlprocessor.HomeTimelineStatusPrepare(&suite.state, suite.tc),
|
||||
tlprocessor.SkipInsert(),
|
||||
)
|
||||
suite.manager = manager
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ func (t *timeline) prepareXBetweenIDs(ctx context.Context, amount int, behindID
|
|||
}
|
||||
|
||||
for e, entry := range toPrepare {
|
||||
prepared, err := t.prepareFunction(ctx, t.accountID, entry.itemID)
|
||||
prepared, err := t.prepareFunction(ctx, t.timelineID, entry.itemID)
|
||||
if err != nil {
|
||||
if errors.Is(err, db.ErrNoEntries) {
|
||||
// ErrNoEntries means something has been deleted,
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/processing"
|
||||
tlprocessor "github.com/superseriousbusiness/gotosocial/internal/processing/timeline"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/timeline"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/visibility"
|
||||
"github.com/superseriousbusiness/gotosocial/testrig"
|
||||
|
|
@ -55,10 +55,10 @@ func (suite *PruneTestSuite) SetupTest() {
|
|||
tl := timeline.NewTimeline(
|
||||
context.Background(),
|
||||
suite.testAccounts["local_account_1"].ID,
|
||||
processing.StatusGrabFunction(suite.db),
|
||||
processing.StatusFilterFunction(suite.db, suite.filter),
|
||||
processing.StatusPrepareFunction(suite.db, suite.tc),
|
||||
processing.StatusSkipInsertFunction(),
|
||||
tlprocessor.HomeTimelineGrab(&suite.state),
|
||||
tlprocessor.HomeTimelineFilter(&suite.state, suite.filter),
|
||||
tlprocessor.HomeTimelineStatusPrepare(&suite.state, suite.tc),
|
||||
tlprocessor.SkipInsert(),
|
||||
)
|
||||
|
||||
// put the status IDs in a determinate order since we can't trust a map to keep its order
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ import (
|
|||
func (t *timeline) Remove(ctx context.Context, statusID string) (int, error) {
|
||||
l := log.WithContext(ctx).
|
||||
WithFields(kv.Fields{
|
||||
{"accountTimeline", t.accountID},
|
||||
{"accountTimeline", t.timelineID},
|
||||
{"statusID", statusID},
|
||||
}...)
|
||||
|
||||
|
|
@ -64,7 +64,7 @@ func (t *timeline) RemoveAllByOrBoosting(ctx context.Context, accountID string)
|
|||
l := log.
|
||||
WithContext(ctx).
|
||||
WithFields(kv.Fields{
|
||||
{"accountTimeline", t.accountID},
|
||||
{"accountTimeline", t.timelineID},
|
||||
{"accountID", accountID},
|
||||
}...)
|
||||
|
||||
|
|
|
|||
|
|
@ -28,24 +28,24 @@ import (
|
|||
// It should be provided to NewTimeline when the caller is creating a timeline
|
||||
// (of statuses, notifications, etc).
|
||||
//
|
||||
// timelineAccountID: the owner of the timeline
|
||||
// maxID: the maximum item ID desired.
|
||||
// sinceID: the minimum item ID desired.
|
||||
// minID: see sinceID
|
||||
// limit: the maximum amount of items to be returned
|
||||
// - timelineID: ID of the timeline.
|
||||
// - maxID: the maximum item ID desired.
|
||||
// - sinceID: the minimum item ID desired.
|
||||
// - minID: see sinceID
|
||||
// - limit: the maximum amount of items to be returned
|
||||
//
|
||||
// If an error is returned, the timeline will stop processing whatever request called GrabFunction,
|
||||
// and return the error. If no error is returned, but stop = true, this indicates to the caller of GrabFunction
|
||||
// that there are no more items to return, and processing should continue with the items already grabbed.
|
||||
type GrabFunction func(ctx context.Context, timelineAccountID string, maxID string, sinceID string, minID string, limit int) (items []Timelineable, stop bool, err error)
|
||||
type GrabFunction func(ctx context.Context, timelineID string, maxID string, sinceID string, minID string, limit int) (items []Timelineable, stop bool, err error)
|
||||
|
||||
// FilterFunction is used by a Timeline to filter whether or not a grabbed item should be indexed.
|
||||
type FilterFunction func(ctx context.Context, timelineAccountID string, item Timelineable) (shouldIndex bool, err error)
|
||||
type FilterFunction func(ctx context.Context, timelineID string, item Timelineable) (shouldIndex bool, err error)
|
||||
|
||||
// PrepareFunction converts a Timelineable into a Preparable.
|
||||
//
|
||||
// For example, this might result in the converstion of a *gtsmodel.Status with the given itemID into a serializable *apimodel.Status.
|
||||
type PrepareFunction func(ctx context.Context, timelineAccountID string, itemID string) (Preparable, error)
|
||||
type PrepareFunction func(ctx context.Context, timelineID string, itemID string) (Preparable, error)
|
||||
|
||||
// SkipInsertFunction indicates whether a new item about to be inserted in the prepared list should be skipped,
|
||||
// based on the item itself, the next item in the timeline, and the depth at which nextItem has been found in the list.
|
||||
|
|
@ -88,8 +88,8 @@ type Timeline interface {
|
|||
INFO FUNCTIONS
|
||||
*/
|
||||
|
||||
// AccountID returns the id of the account this timeline belongs to.
|
||||
AccountID() string
|
||||
// TimelineID returns the id of this timeline.
|
||||
TimelineID() string
|
||||
|
||||
// Len returns the length of the item index at this point in time.
|
||||
Len() int
|
||||
|
|
@ -130,19 +130,20 @@ type timeline struct {
|
|||
grabFunction GrabFunction
|
||||
filterFunction FilterFunction
|
||||
prepareFunction PrepareFunction
|
||||
accountID string
|
||||
timelineID string
|
||||
lastGot time.Time
|
||||
sync.Mutex
|
||||
}
|
||||
|
||||
func (t *timeline) AccountID() string {
|
||||
return t.accountID
|
||||
func (t *timeline) TimelineID() string {
|
||||
return t.timelineID
|
||||
}
|
||||
|
||||
// NewTimeline returns a new Timeline for the given account ID
|
||||
// NewTimeline returns a new Timeline with
|
||||
// the given ID, using the given functions.
|
||||
func NewTimeline(
|
||||
ctx context.Context,
|
||||
timelineAccountID string,
|
||||
timelineID string,
|
||||
grabFunction GrabFunction,
|
||||
filterFunction FilterFunction,
|
||||
prepareFunction PrepareFunction,
|
||||
|
|
@ -155,7 +156,7 @@ func NewTimeline(
|
|||
grabFunction: grabFunction,
|
||||
filterFunction: filterFunction,
|
||||
prepareFunction: prepareFunction,
|
||||
accountID: timelineAccountID,
|
||||
timelineID: timelineID,
|
||||
lastGot: time.Time{},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
37
internal/timeline/timelines.go
Normal file
37
internal/timeline/timelines.go
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
// GoToSocial
|
||||
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package timeline
|
||||
|
||||
type Timelines struct {
|
||||
// Home provides access to account home timelines.
|
||||
Home Manager
|
||||
|
||||
// List provides access to list timelines.
|
||||
List Manager
|
||||
|
||||
// prevent pass-by-value.
|
||||
_ nocopy
|
||||
}
|
||||
|
||||
// nocopy when embedded will signal linter to
|
||||
// error on pass-by-value of parent struct.
|
||||
type nocopy struct{}
|
||||
|
||||
func (*nocopy) Lock() {}
|
||||
|
||||
func (*nocopy) Unlock() {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue