diff options
Diffstat (limited to 'internal/db')
-rw-r--r-- | internal/db/db.go | 8 | ||||
-rw-r--r-- | internal/db/pg/pg.go | 20 |
2 files changed, 27 insertions, 1 deletions
diff --git a/internal/db/db.go b/internal/db/db.go index 5609b926f..e43318c58 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -32,18 +32,20 @@ const ( // ErrNoEntries is to be returned from the DB interface when no entries are found for a given query. type ErrNoEntries struct{} + func (e ErrNoEntries) Error() string { return "no entries" } // ErrAlreadyExists is to be returned from the DB interface when an entry already exists for a given query or its constraints. type ErrAlreadyExists struct{} + func (e ErrAlreadyExists) Error() string { return "already exists" } type Where struct { - Key string + Key string Value interface{} } @@ -278,6 +280,10 @@ type DB interface { // This slice will be unfiltered, not taking account of blocks and whatnot, so filter it before serving it back to a user. WhoFavedStatus(status *gtsmodel.Status) ([]*gtsmodel.Account, error) + // GetHomeTimelineForAccount fetches the account's HOME timeline -- ie., posts and replies from people they *follow*. + // It will use the given filters and try to return as many statuses up to the limit as possible. + GetHomeTimelineForAccount(accountID string, maxID string, sinceID string, minID string, limit int, local bool) ([]*gtsmodel.Status, error) + /* USEFUL CONVERSION FUNCTIONS */ diff --git a/internal/db/pg/pg.go b/internal/db/pg/pg.go index 2a4b040d1..30b073bcc 100644 --- a/internal/db/pg/pg.go +++ b/internal/db/pg/pg.go @@ -1103,6 +1103,26 @@ func (ps *postgresService) WhoFavedStatus(status *gtsmodel.Status) ([]*gtsmodel. return accounts, nil } +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). + ColumnExpr("status.*"). + Join("JOIN follows AS f ON f.target_account_id = status.account_id"). + Where("f.account_id = ?", accountID). + Limit(limit). + Order("status.created_at DESC") + + err := q.Select() + if err != nil { + if err != pg.ErrNoRows { + return nil, err + } + } + + return statuses, nil +} + /* CONVERSION FUNCTIONS */ |