diff options
author | 2021-08-15 18:43:08 +0200 | |
---|---|---|
committer | 2021-08-15 18:43:08 +0200 | |
commit | ff406be68f0fe6fc0b2dae9a091ce164ac039b3f (patch) | |
tree | 622473ad500239f890b116f8bd30164b92a7dfc5 /internal/db/pg/timeline.go | |
parent | Don't run tests+lint on merge to main (#139) (diff) | |
download | gotosocial-ff406be68f0fe6fc0b2dae9a091ce164ac039b3f.tar.xz |
Timeline loop fix (#140)
* uwu we made a fucky wucky
* uwu we made a fucky wucky
* work on timeline fixes a little
* fiddle with tests some more
* bleep bloop more tests
* more tests
* update drone yml
* update some sturf
* make the timeline code a bit lazier
* go fmt
* fix drone.yml
Diffstat (limited to 'internal/db/pg/timeline.go')
-rw-r--r-- | internal/db/pg/timeline.go | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/internal/db/pg/timeline.go b/internal/db/pg/timeline.go index 95acd4f38..585ca3067 100644 --- a/internal/db/pg/timeline.go +++ b/internal/db/pg/timeline.go @@ -28,31 +28,46 @@ import ( func (ps *postgresService) GetHomeTimelineForAccount(accountID string, maxID string, sinceID string, minID string, limit int, local bool) ([]*gtsmodel.Status, error) { statuses := []*gtsmodel.Status{} - q := ps.conn.Model(&statuses) q = q.ColumnExpr("status.*"). + // Find out who accountID follows. Join("LEFT JOIN follows AS f ON f.target_account_id = status.account_id"). - Where("f.account_id = ?", accountID). + // Use a WhereGroup here to specify that we want EITHER statuses posted by accounts that accountID follows, + // OR statuses posted by accountID itself (since a user should be able to see their own statuses). + // + // This is equivalent to something like WHERE ... AND (... OR ...) + // See: https://pg.uptrace.dev/queries/#select + WhereGroup(func(q *pg.Query) (*pg.Query, error) { + q = q.WhereOr("f.account_id = ?", accountID). + WhereOr("status.account_id = ?", accountID) + return q, nil + }). + // 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("status.id < ?", maxID) } if sinceID != "" { + // return only statuses HIGHER (ie., newer) than sinceID q = q.Where("status.id > ?", sinceID) } if minID != "" { + // return only statuses HIGHER (ie., newer) than minID q = q.Where("status.id > ?", minID) } if local { + // return only statuses posted by local account havers q = q.Where("status.local = ?", local) } if limit > 0 { + // limit amount of statuses returned q = q.Limit(limit) } |