mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-29 17:46:15 -06:00
uwu we made a fucky wucky
This commit is contained in:
parent
a4a33b9ad9
commit
778c8377e4
2 changed files with 7 additions and 26 deletions
|
|
@ -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
|
// maxID isn't defined, but sinceID || minID are, so take x before
|
||||||
if maxID == "" && sinceID != "" {
|
if maxID == "" && sinceID != "" {
|
||||||
attempts := 0
|
statuses, err = t.GetXBeforeID(amount, sinceID, true)
|
||||||
statuses, err = t.GetXBeforeID(amount, sinceID, true, &attempts)
|
|
||||||
}
|
}
|
||||||
if maxID == "" && minID != "" {
|
if maxID == "" && minID != "" {
|
||||||
attempts := 0
|
statuses, err = t.GetXBeforeID(amount, minID, true)
|
||||||
statuses, err = t.GetXBeforeID(amount, minID, true, &attempts)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return statuses, err
|
return statuses, err
|
||||||
|
|
@ -203,11 +201,7 @@ serveloop:
|
||||||
return statuses, nil
|
return statuses, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timeline) GetXBeforeID(amount int, beforeID string, startFromTop bool, attempts *int) ([]*apimodel.Status, error) {
|
func (t *timeline) GetXBeforeID(amount int, beforeID string, startFromTop bool) ([]*apimodel.Status, error) {
|
||||||
newAttempts := *attempts
|
|
||||||
newAttempts = newAttempts + 1
|
|
||||||
attempts = &newAttempts
|
|
||||||
|
|
||||||
// make a slice of statuses with the length we need to return
|
// make a slice of statuses with the length we need to return
|
||||||
statuses := make([]*apimodel.Status, 0, amount)
|
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{}
|
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
|
var beforeIDMark *list.Element
|
||||||
findMarkLoop:
|
findMarkLoop:
|
||||||
for e := t.preparedPosts.data.Front(); e != nil; e = e.Next() {
|
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")
|
return nil, errors.New("GetXBeforeID: could not parse e as a preparedPostsEntry")
|
||||||
}
|
}
|
||||||
|
|
||||||
if entry.statusID == beforeID {
|
if entry.statusID >= beforeID {
|
||||||
beforeIDMark = e
|
beforeIDMark = e
|
||||||
|
} else {
|
||||||
break findMarkLoop
|
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
|
var served int
|
||||||
|
|
||||||
if startFromTop {
|
if startFromTop {
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ type Timeline interface {
|
||||||
// This will NOT include the status with the given ID.
|
// This will NOT include the status with the given ID.
|
||||||
//
|
//
|
||||||
// This corresponds to an api call to /timelines/home?since_id=WHATEVER
|
// 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.
|
// 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 will NOT include the status with the given IDs.
|
||||||
//
|
//
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue