summaryrefslogtreecommitdiff
path: root/internal/db/pg
diff options
context:
space:
mode:
Diffstat (limited to 'internal/db/pg')
-rw-r--r--internal/db/pg/instance.go (renamed from internal/db/pg/instancestats.go)31
-rw-r--r--internal/db/pg/pg.go33
2 files changed, 53 insertions, 11 deletions
diff --git a/internal/db/pg/instancestats.go b/internal/db/pg/instance.go
index b57591d7b..2de0c5366 100644
--- a/internal/db/pg/instancestats.go
+++ b/internal/db/pg/instance.go
@@ -2,6 +2,7 @@ package pg
import (
"github.com/go-pg/pg/v10"
+ "github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
)
@@ -50,3 +51,33 @@ func (ps *postgresService) GetDomainCountForInstance(domain string) (int, error)
return q.Count()
}
+
+func (ps *postgresService) GetAccountsForInstance(domain string, maxID string, limit int) ([]*gtsmodel.Account, error) {
+ ps.log.Debug("GetAccountsForInstance")
+
+ accounts := []*gtsmodel.Account{}
+
+ q := ps.conn.Model(&accounts).Where("domain = ?", domain).Order("id DESC")
+
+ if maxID != "" {
+ q = q.Where("id < ?", maxID)
+ }
+
+ if limit > 0 {
+ q = q.Limit(limit)
+ }
+
+ err := q.Select()
+ if err != nil {
+ if err == pg.ErrNoRows {
+ return nil, db.ErrNoEntries{}
+ }
+ return nil, err
+ }
+
+ if len(accounts) == 0 {
+ return nil, db.ErrNoEntries{}
+ }
+
+ return accounts, nil
+}
diff --git a/internal/db/pg/pg.go b/internal/db/pg/pg.go
index 2758d3c3d..1050f141e 100644
--- a/internal/db/pg/pg.go
+++ b/internal/db/pg/pg.go
@@ -511,39 +511,50 @@ func (ps *postgresService) CountStatusesByAccountID(accountID string) (int, erro
return count, nil
}
-func (ps *postgresService) GetStatusesByTimeDescending(accountID string, statuses *[]gtsmodel.Status, limit int, excludeReplies bool, maxID string, pinned bool, mediaOnly bool) error {
- q := ps.conn.Model(statuses).Order("created_at DESC")
+func (ps *postgresService) GetStatusesForAccount(accountID string, limit int, excludeReplies bool, maxID string, pinnedOnly bool, mediaOnly bool) ([]*gtsmodel.Status, error) {
+ ps.log.Debugf("getting statuses for account %s", accountID)
+ statuses := []*gtsmodel.Status{}
+
+ q := ps.conn.Model(&statuses).Order("id DESC")
if accountID != "" {
q = q.Where("account_id = ?", accountID)
}
+
if limit != 0 {
q = q.Limit(limit)
}
+
if excludeReplies {
q = q.Where("? IS NULL", pg.Ident("in_reply_to_id"))
}
- if pinned {
+
+ if pinnedOnly {
q = q.Where("pinned = ?", true)
}
+
if mediaOnly {
q = q.WhereGroup(func(q *pg.Query) (*pg.Query, error) {
return q.Where("? IS NOT NULL", pg.Ident("attachments")).Where("attachments != '{}'"), nil
})
}
+
if maxID != "" {
- s := &gtsmodel.Status{}
- if err := ps.conn.Model(s).Where("id = ?", maxID).Select(); err != nil {
- return err
- }
- q = q.Where("status.created_at < ?", s.CreatedAt)
+ q = q.Where("id < ?", maxID)
}
+
if err := q.Select(); err != nil {
if err == pg.ErrNoRows {
- return db.ErrNoEntries{}
+ return nil, db.ErrNoEntries{}
}
- return err
+ return nil, err
}
- return nil
+
+ if len(statuses) == 0 {
+ return nil, db.ErrNoEntries{}
+ }
+
+ ps.log.Debugf("returning statuses for account %s", accountID)
+ return statuses, nil
}
func (ps *postgresService) GetLastStatusForAccountID(accountID string, status *gtsmodel.Status) error {