diff options
Diffstat (limited to 'internal/timeline/timeline.go')
-rw-r--r-- | internal/timeline/timeline.go | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/internal/timeline/timeline.go b/internal/timeline/timeline.go index 6274a86ac..5f5fa1b4f 100644 --- a/internal/timeline/timeline.go +++ b/internal/timeline/timeline.go @@ -19,6 +19,7 @@ package timeline import ( + "context" "sync" "time" @@ -41,24 +42,24 @@ type Timeline interface { // Get returns an amount of statuses with the given parameters. // If prepareNext is true, then the next predicted query will be prepared already in a goroutine, // to make the next call to Get faster. - Get(amount int, maxID string, sinceID string, minID string, prepareNext bool) ([]*apimodel.Status, error) + Get(ctx context.Context, amount int, maxID string, sinceID string, minID string, prepareNext bool) ([]*apimodel.Status, error) // GetXFromTop returns x amount of posts from the top of the timeline, from newest to oldest. - GetXFromTop(amount int) ([]*apimodel.Status, error) + GetXFromTop(ctx context.Context, amount int) ([]*apimodel.Status, error) // GetXBehindID returns x amount of posts from the given id onwards, from newest to oldest. // This will NOT include the status with the given ID. // // This corresponds to an api call to /timelines/home?max_id=WHATEVER - GetXBehindID(amount int, fromID string, attempts *int) ([]*apimodel.Status, error) + GetXBehindID(ctx context.Context, amount int, fromID string, attempts *int) ([]*apimodel.Status, error) // GetXBeforeID returns x amount of posts up to the given id, from newest to oldest. // This will NOT include the status with the given ID. // // This corresponds to an api call to /timelines/home?since_id=WHATEVER - GetXBeforeID(amount int, sinceID string, startFromTop bool) ([]*apimodel.Status, error) + GetXBeforeID(ctx context.Context, amount int, sinceID string, startFromTop bool) ([]*apimodel.Status, error) // GetXBetweenID returns x amount of posts from the given maxID, up to the given id, from newest to oldest. // This will NOT include the status with the given IDs. // // This corresponds to an api call to /timelines/home?since_id=WHATEVER&max_id=WHATEVER_ELSE - GetXBetweenID(amount int, maxID string, sinceID string) ([]*apimodel.Status, error) + GetXBetweenID(ctx context.Context, amount int, maxID string, sinceID string) ([]*apimodel.Status, error) /* INDEXING FUNCTIONS @@ -68,43 +69,43 @@ type Timeline interface { // // The returned bool indicates whether or not the status was actually inserted into the timeline. This will be false // if the status is a boost and the original post or another boost of it already exists < boostReinsertionDepth back in the timeline. - IndexOne(statusCreatedAt time.Time, statusID string, boostOfID string, accountID string, boostOfAccountID string) (bool, error) + IndexOne(ctx context.Context, statusCreatedAt time.Time, statusID string, boostOfID string, accountID string, boostOfAccountID string) (bool, error) // OldestIndexedPostID returns the id of the rearmost (ie., the oldest) indexed post, or an error if something goes wrong. // If nothing goes wrong but there's no oldest post, an empty string will be returned so make sure to check for this. - OldestIndexedPostID() (string, error) + OldestIndexedPostID(ctx context.Context) (string, error) // NewestIndexedPostID returns the id of the frontmost (ie., the newest) indexed post, or an error if something goes wrong. // If nothing goes wrong but there's no newest post, an empty string will be returned so make sure to check for this. - NewestIndexedPostID() (string, error) + NewestIndexedPostID(ctx context.Context) (string, error) - IndexBefore(statusID string, include bool, amount int) error - IndexBehind(statusID string, include bool, amount int) error + IndexBefore(ctx context.Context, statusID string, include bool, amount int) error + IndexBehind(ctx context.Context, statusID string, include bool, amount int) error /* PREPARATION FUNCTIONS */ // PrepareXFromTop instructs the timeline to prepare x amount of posts from the top of the timeline. - PrepareFromTop(amount int) error + PrepareFromTop(ctx context.Context, amount int) error // PrepareBehind instructs the timeline to prepare the next amount of entries for serialization, from position onwards. // If include is true, then the given status ID will also be prepared, otherwise only entries behind it will be prepared. - PrepareBehind(statusID string, amount int) error + PrepareBehind(ctx context.Context, statusID string, amount int) error // IndexOne puts a status into the timeline at the appropriate place according to its 'createdAt' property, // and then immediately prepares it. // // The returned bool indicates whether or not the status was actually inserted into the timeline. This will be false // if the status is a boost and the original post or another boost of it already exists < boostReinsertionDepth back in the timeline. - IndexAndPrepareOne(statusCreatedAt time.Time, statusID string, boostOfID string, accountID string, boostOfAccountID string) (bool, error) + IndexAndPrepareOne(ctx context.Context, statusCreatedAt time.Time, statusID string, boostOfID string, accountID string, boostOfAccountID string) (bool, error) // OldestPreparedPostID returns the id of the rearmost (ie., the oldest) prepared post, or an error if something goes wrong. // If nothing goes wrong but there's no oldest post, an empty string will be returned so make sure to check for this. - OldestPreparedPostID() (string, error) + OldestPreparedPostID(ctx context.Context) (string, error) /* INFO FUNCTIONS */ // ActualPostIndexLength returns the actual length of the post index at this point in time. - PostIndexLength() int + PostIndexLength(ctx context.Context) int /* UTILITY FUNCTIONS @@ -117,11 +118,11 @@ type Timeline interface { // If a status has multiple entries in a timeline, they will all be removed. // // The returned int indicates the amount of entries that were removed. - Remove(statusID string) (int, error) + Remove(ctx context.Context, statusID string) (int, error) // RemoveAllBy removes all statuses by the given accountID, from both the index and prepared posts. // // The returned int indicates the amount of entries that were removed. - RemoveAllBy(accountID string) (int, error) + RemoveAllBy(ctx context.Context, accountID string) (int, error) } // timeline fulfils the Timeline interface @@ -138,9 +139,9 @@ type timeline struct { } // NewTimeline returns a new Timeline for the given account ID -func NewTimeline(accountID string, db db.DB, typeConverter typeutils.TypeConverter, log *logrus.Logger) (Timeline, error) { +func NewTimeline(ctx context.Context, accountID string, db db.DB, typeConverter typeutils.TypeConverter, log *logrus.Logger) (Timeline, error) { timelineOwnerAccount := >smodel.Account{} - if err := db.GetByID(accountID, timelineOwnerAccount); err != nil { + if err := db.GetByID(ctx, accountID, timelineOwnerAccount); err != nil { return nil, err } @@ -160,7 +161,7 @@ func (t *timeline) Reset() error { return nil } -func (t *timeline) PostIndexLength() int { +func (t *timeline) PostIndexLength(ctx context.Context) int { if t.postIndex == nil || t.postIndex.data == nil { return 0 } |