diff --git a/internal/timeline/get.go b/internal/timeline/get.go index 9d6c6efbf..048b832af 100644 --- a/internal/timeline/get.go +++ b/internal/timeline/get.go @@ -82,12 +82,10 @@ func (t *timeline) Get(amount int, maxID string, sinceID string, minID string) ( // maxID isn't defined, but sinceID || minID are, so take x before if maxID == "" && sinceID != "" { - attempts := 0 - statuses, err = t.GetXBeforeID(amount, sinceID, true, &attempts) + statuses, err = t.GetXBeforeID(amount, sinceID, true) } if maxID == "" && minID != "" { - attempts := 0 - statuses, err = t.GetXBeforeID(amount, minID, true, &attempts) + statuses, err = t.GetXBeforeID(amount, minID, true) } return statuses, err @@ -203,11 +201,7 @@ serveloop: return statuses, nil } -func (t *timeline) GetXBeforeID(amount int, beforeID string, startFromTop bool, attempts *int) ([]*apimodel.Status, error) { - newAttempts := *attempts - newAttempts = newAttempts + 1 - attempts = &newAttempts - +func (t *timeline) GetXBeforeID(amount int, beforeID string, startFromTop bool) ([]*apimodel.Status, error) { // make a slice of statuses with the length we need to return statuses := make([]*apimodel.Status, 0, amount) @@ -215,7 +209,7 @@ func (t *timeline) GetXBeforeID(amount int, beforeID string, startFromTop bool, t.preparedPosts.data = &list.List{} } - // iterate through the modified list until we hit the mark we're looking for + // iterate through the modified list until we hit the mark we're looking for, or as close as possible to it var beforeIDMark *list.Element findMarkLoop: for e := t.preparedPosts.data.Front(); e != nil; e = e.Next() { @@ -224,26 +218,13 @@ findMarkLoop: return nil, errors.New("GetXBeforeID: could not parse e as a preparedPostsEntry") } - if entry.statusID == beforeID { + if entry.statusID >= beforeID { beforeIDMark = e + } else { break findMarkLoop } } - // we didn't find it, so we need to make sure it's indexed and prepared and then try again - if beforeIDMark == nil { - if err := t.IndexBefore(beforeID, true, amount); err != nil { - return nil, fmt.Errorf("GetXBeforeID: error indexing before and including ID %s", beforeID) - } - if err := t.PrepareBefore(beforeID, true, amount); err != nil { - return nil, fmt.Errorf("GetXBeforeID: error preparing before and including ID %s", beforeID) - } - if *attempts > retries { - return statuses, nil - } - return t.GetXBeforeID(amount, beforeID, startFromTop, attempts) - } - var served int if startFromTop { diff --git a/internal/timeline/timeline.go b/internal/timeline/timeline.go index 20015a745..0c749ec96 100644 --- a/internal/timeline/timeline.go +++ b/internal/timeline/timeline.go @@ -50,7 +50,7 @@ type Timeline interface { // 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, attempts *int) ([]*apimodel.Status, error) + GetXBeforeID(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. //