summaryrefslogtreecommitdiff
path: root/internal/db/bundb/timeline.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/db/bundb/timeline.go')
-rw-r--r--internal/db/bundb/timeline.go27
1 files changed, 22 insertions, 5 deletions
diff --git a/internal/db/bundb/timeline.go b/internal/db/bundb/timeline.go
index d4740dd96..35b754d73 100644
--- a/internal/db/bundb/timeline.go
+++ b/internal/db/bundb/timeline.go
@@ -20,9 +20,11 @@ package bundb
import (
"context"
+ "time"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/internal/id"
"github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/uptrace/bun"
"golang.org/x/exp/slices"
@@ -58,11 +60,18 @@ func (t *timelineDB) GetHomeTimeline(ctx context.Context, accountID string, maxI
// Sort by highest ID (newest) to lowest ID (oldest)
Order("status.id DESC")
- if maxID != "" {
- // return only statuses LOWER (ie., older) than maxID
- q = q.Where("? < ?", bun.Ident("status.id"), maxID)
+ if maxID == "" {
+ var err error
+ // don't return statuses more than five minutes in the future
+ maxID, err = id.NewULIDFromTime(time.Now().Add(5 * time.Minute))
+ if err != nil {
+ return nil, err
+ }
}
+ // return only statuses LOWER (ie., older) than maxID
+ q = q.Where("? < ?", bun.Ident("status.id"), maxID)
+
if sinceID != "" {
// return only statuses HIGHER (ie., newer) than sinceID
q = q.Where("? > ?", bun.Ident("status.id"), sinceID)
@@ -134,10 +143,18 @@ func (t *timelineDB) GetPublicTimeline(ctx context.Context, accountID string, ma
WhereGroup(" AND ", whereEmptyOrNull("status.boost_of_id")).
Order("status.id DESC")
- if maxID != "" {
- q = q.Where("? < ?", bun.Ident("status.id"), maxID)
+ if maxID == "" {
+ var err error
+ // don't return statuses more than five minutes in the future
+ maxID, err = id.NewULIDFromTime(time.Now().Add(5 * time.Minute))
+ if err != nil {
+ return nil, err
+ }
}
+ // return only statuses LOWER (ie., older) than maxID
+ q = q.Where("? < ?", bun.Ident("status.id"), maxID)
+
if sinceID != "" {
q = q.Where("? > ?", bun.Ident("status.id"), sinceID)
}