Timeline bugfix (#60)

* fix a stack overflow in the timeline

* go fmt
This commit is contained in:
Tobi Smethurst 2021-06-23 18:42:20 +02:00 committed by GitHub
commit 16e486ad96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 100 additions and 26 deletions

View file

@ -10,6 +10,45 @@ import (
)
func (t *timeline) IndexBefore(statusID string, include bool, amount int) error {
filtered := []*gtsmodel.Status{}
offsetStatus := statusID
if include {
s := &gtsmodel.Status{}
if err := t.db.GetByID(statusID, s); err != nil {
return fmt.Errorf("IndexBefore: error getting initial status with id %s: %s", statusID, err)
}
filtered = append(filtered, s)
}
grabloop:
for len(filtered) < amount {
statuses, err := t.db.GetStatusesWhereFollowing(t.accountID, "", offsetStatus, "", amount, false)
if err != nil {
if _, ok := err.(db.ErrNoEntries); ok {
break grabloop // we just don't have enough statuses left in the db so index what we've got and then bail
}
return fmt.Errorf("IndexBefore: error getting statuses from db: %s", err)
}
for _, s := range statuses {
timelineable, err := t.filter.StatusHometimelineable(s, t.account)
if err != nil {
continue
}
if timelineable {
filtered = append(filtered, s)
}
offsetStatus = s.ID
}
}
for _, s := range filtered {
if _, err := t.IndexOne(s.CreatedAt, s.ID, s.BoostOfID); err != nil {
return fmt.Errorf("IndexBefore: error indexing status with id %s: %s", s.ID, err)
}
}
return nil
}
@ -41,7 +80,7 @@ grabloop:
for _, s := range filtered {
if _, err := t.IndexOne(s.CreatedAt, s.ID, s.BoostOfID); err != nil {
return fmt.Errorf("IndexBehindAndIncluding: error indexing status with id %s: %s", s.ID, err)
return fmt.Errorf("IndexBehind: error indexing status with id %s: %s", s.ID, err)
}
}