mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2026-01-05 21:53:15 -06:00
rename some stuff
This commit is contained in:
parent
a2c4c0ec03
commit
32ed58a100
33 changed files with 203 additions and 114 deletions
|
|
@ -149,14 +149,16 @@ func (a *accountDB) GetLocalAccountByUsername(username string) (*gtsmodel.Accoun
|
|||
return account, err
|
||||
}
|
||||
|
||||
func (a *accountDB) GetAccountFollowRequests(accountID string, followRequests *[]gtsmodel.FollowRequest) db.Error {
|
||||
if err := a.conn.Model(followRequests).Where("target_account_id = ?", accountID).Select(); err != nil {
|
||||
if err == pg.ErrNoRows {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
func (a *accountDB) GetAccountFollowRequests(accountID string) ([]*gtsmodel.FollowRequest, db.Error) {
|
||||
followRequests := []*gtsmodel.FollowRequest{}
|
||||
|
||||
q := a.conn.
|
||||
Model(&followRequests).
|
||||
Where("target_account_id = ?", accountID)]
|
||||
|
||||
err := processErrorResponse(q.Select())
|
||||
|
||||
return followRequests, err
|
||||
}
|
||||
|
||||
func (a *accountDB) GetAccountFollowing(accountID string, following *[]gtsmodel.Follow) db.Error {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ type instanceDB struct {
|
|||
cancel context.CancelFunc
|
||||
}
|
||||
|
||||
func (i *instanceDB) GetUserCountForInstance(domain string) (int, db.Error) {
|
||||
func (i *instanceDB) CountInstanceUsers(domain string) (int, db.Error) {
|
||||
q := i.conn.Model(&[]*gtsmodel.Account{})
|
||||
|
||||
if domain == i.config.Host {
|
||||
|
|
@ -51,7 +51,7 @@ func (i *instanceDB) GetUserCountForInstance(domain string) (int, db.Error) {
|
|||
return q.Count()
|
||||
}
|
||||
|
||||
func (i *instanceDB) GetStatusCountForInstance(domain string) (int, db.Error) {
|
||||
func (i *instanceDB) CountInstanceStatuses(domain string) (int, db.Error) {
|
||||
q := i.conn.Model(&[]*gtsmodel.Status{})
|
||||
|
||||
if domain == i.config.Host {
|
||||
|
|
@ -66,7 +66,7 @@ func (i *instanceDB) GetStatusCountForInstance(domain string) (int, db.Error) {
|
|||
return q.Count()
|
||||
}
|
||||
|
||||
func (i *instanceDB) GetDomainCountForInstance(domain string) (int, db.Error) {
|
||||
func (i *instanceDB) CountInstanceDomains(domain string) (int, db.Error) {
|
||||
q := i.conn.Model(&[]*gtsmodel.Instance{})
|
||||
|
||||
if domain == i.config.Host {
|
||||
|
|
@ -81,7 +81,7 @@ func (i *instanceDB) GetDomainCountForInstance(domain string) (int, db.Error) {
|
|||
return q.Count()
|
||||
}
|
||||
|
||||
func (i *instanceDB) GetAccountsForInstance(domain string, maxID string, limit int) ([]*gtsmodel.Account, db.Error) {
|
||||
func (i *instanceDB) GetInstanceAccounts(domain string, maxID string, limit int) ([]*gtsmodel.Account, db.Error) {
|
||||
i.log.Debug("GetAccountsForInstance")
|
||||
|
||||
accounts := []*gtsmodel.Account{}
|
||||
|
|
|
|||
|
|
@ -19,15 +19,88 @@
|
|||
package pg
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/go-pg/pg/v10"
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/cache"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
)
|
||||
|
||||
func (ps *postgresService) GetNotificationsForAccount(accountID string, limit int, maxID string, sinceID string) ([]*gtsmodel.Notification, db.Error) {
|
||||
notifications := []*gtsmodel.Notification{}
|
||||
type notificationDB struct {
|
||||
config *config.Config
|
||||
conn *pg.DB
|
||||
log *logrus.Logger
|
||||
cancel context.CancelFunc
|
||||
cache cache.Cache
|
||||
}
|
||||
|
||||
q := ps.conn.Model(¬ifications).Where("target_account_id = ?", accountID)
|
||||
func (n *notificationDB) cacheNotification(id string, notification *gtsmodel.Notification) {
|
||||
if n.cache == nil {
|
||||
n.cache = cache.New()
|
||||
}
|
||||
|
||||
if err := n.cache.Store(id, notification); err != nil {
|
||||
n.log.Panicf("notificationDB: error storing in cache: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (n *notificationDB) notificationCached(id string) (*gtsmodel.Notification, bool) {
|
||||
if n.cache == nil {
|
||||
n.cache = cache.New()
|
||||
return nil, false
|
||||
}
|
||||
|
||||
nI, err := n.cache.Fetch(id)
|
||||
if err != nil || nI == nil {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
notification, ok := nI.(*gtsmodel.Notification)
|
||||
if !ok {
|
||||
n.log.Panicf("notificationDB: cached interface with key %s was not a notification", id)
|
||||
}
|
||||
|
||||
return notification, true
|
||||
}
|
||||
|
||||
func (n *notificationDB) newNotificationQ(i interface{}) *orm.Query {
|
||||
return n.conn.Model(i).
|
||||
Relation("OriginAccount").
|
||||
Relation("TargetAccount").
|
||||
Relation("Status")
|
||||
}
|
||||
|
||||
func (n *notificationDB) GetNotification(id string) (*gtsmodel.Notification, db.Error) {
|
||||
if notification, cached := n.notificationCached(id); cached {
|
||||
return notification, nil
|
||||
}
|
||||
|
||||
notification := >smodel.Notification{}
|
||||
|
||||
q := n.newNotificationQ(notification).
|
||||
Where("notification.id = ?", id)
|
||||
|
||||
err := processErrorResponse(q.Select())
|
||||
|
||||
if err == nil && notification != nil {
|
||||
n.cacheNotification(id, notification)
|
||||
}
|
||||
|
||||
return notification, err
|
||||
}
|
||||
|
||||
func (n *notificationDB) GetNotifications(accountID string, limit int, maxID string, sinceID string) ([]*gtsmodel.Notification, db.Error) {
|
||||
// begin by selecting just the IDs
|
||||
notifIDs := []*gtsmodel.Notification{}
|
||||
q := n.conn.
|
||||
Model(¬ifIDs).
|
||||
Column("id").
|
||||
Where("target_account_id = ?", accountID).
|
||||
Order("id DESC")
|
||||
|
||||
if maxID != "" {
|
||||
q = q.Where("id < ?", maxID)
|
||||
|
|
@ -41,13 +114,22 @@ func (ps *postgresService) GetNotificationsForAccount(accountID string, limit in
|
|||
q = q.Limit(limit)
|
||||
}
|
||||
|
||||
q = q.Order("created_at DESC")
|
||||
|
||||
if err := q.Select(); err != nil {
|
||||
if err != pg.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err := processErrorResponse(q.Select())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// now we have the IDs, select the notifs one by one
|
||||
// reason for this is that for each notif, we can instead get it from our cache if it's cached
|
||||
notifications := []*gtsmodel.Notification{}
|
||||
for _, notifID := range notifIDs {
|
||||
notif, err := n.GetNotification(notifID.ID)
|
||||
errP := processErrorResponse(err)
|
||||
if errP != nil {
|
||||
return nil, errP
|
||||
}
|
||||
notifications = append(notifications, notif)
|
||||
}
|
||||
|
||||
return notifications, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -148,6 +148,12 @@ func NewPostgresService(ctx context.Context, c *config.Config, log *logrus.Logge
|
|||
log: log,
|
||||
cancel: cancel,
|
||||
},
|
||||
Notification: ¬ificationDB{
|
||||
config: c,
|
||||
conn: conn,
|
||||
log: log,
|
||||
cancel: cancel,
|
||||
},
|
||||
Relationship: &relationshipDB{
|
||||
config: c,
|
||||
conn: conn,
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ func (r *relationshipDB) processResponse(block *gtsmodel.Block, err error) (*gts
|
|||
}
|
||||
}
|
||||
|
||||
func (r *relationshipDB) Blocked(account1 string, account2 string, eitherDirection bool) (bool, db.Error) {
|
||||
func (r *relationshipDB) IsBlocked(account1 string, account2 string, eitherDirection bool) (bool, db.Error) {
|
||||
q := r.conn.Model(>smodel.Block{}).Where("account_id = ?", account1).Where("target_account_id = ?", account2)
|
||||
|
||||
if eitherDirection {
|
||||
|
|
@ -128,7 +128,7 @@ func (r *relationshipDB) GetRelationship(requestingAccount string, targetAccount
|
|||
return rel, nil
|
||||
}
|
||||
|
||||
func (r *relationshipDB) Follows(sourceAccount *gtsmodel.Account, targetAccount *gtsmodel.Account) (bool, db.Error) {
|
||||
func (r *relationshipDB) IsFollowing(sourceAccount *gtsmodel.Account, targetAccount *gtsmodel.Account) (bool, db.Error) {
|
||||
if sourceAccount == nil || targetAccount == nil {
|
||||
return false, nil
|
||||
}
|
||||
|
|
@ -136,7 +136,7 @@ func (r *relationshipDB) Follows(sourceAccount *gtsmodel.Account, targetAccount
|
|||
return r.conn.Model(>smodel.Follow{}).Where("account_id = ?", sourceAccount.ID).Where("target_account_id = ?", targetAccount.ID).Exists()
|
||||
}
|
||||
|
||||
func (r *relationshipDB) FollowRequested(sourceAccount *gtsmodel.Account, targetAccount *gtsmodel.Account) (bool, db.Error) {
|
||||
func (r *relationshipDB) IsFollowRequested(sourceAccount *gtsmodel.Account, targetAccount *gtsmodel.Account) (bool, db.Error) {
|
||||
if sourceAccount == nil || targetAccount == nil {
|
||||
return false, nil
|
||||
}
|
||||
|
|
@ -144,7 +144,7 @@ func (r *relationshipDB) FollowRequested(sourceAccount *gtsmodel.Account, target
|
|||
return r.conn.Model(>smodel.FollowRequest{}).Where("account_id = ?", sourceAccount.ID).Where("target_account_id = ?", targetAccount.ID).Exists()
|
||||
}
|
||||
|
||||
func (r *relationshipDB) Mutuals(account1 *gtsmodel.Account, account2 *gtsmodel.Account) (bool, db.Error) {
|
||||
func (r *relationshipDB) IsMutualFollowing(account1 *gtsmodel.Account, account2 *gtsmodel.Account) (bool, db.Error) {
|
||||
if account1 == nil || account2 == nil {
|
||||
return false, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ type timelineDB struct {
|
|||
cancel context.CancelFunc
|
||||
}
|
||||
|
||||
func (t *timelineDB) GetHomeTimelineForAccount(accountID string, maxID string, sinceID string, minID string, limit int, local bool) ([]*gtsmodel.Status, db.Error) {
|
||||
func (t *timelineDB) GetHomeTimeline(accountID string, maxID string, sinceID string, minID string, limit int, local bool) ([]*gtsmodel.Status, db.Error) {
|
||||
statuses := []*gtsmodel.Status{}
|
||||
q := t.conn.Model(&statuses)
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ func (t *timelineDB) GetHomeTimelineForAccount(accountID string, maxID string, s
|
|||
return statuses, nil
|
||||
}
|
||||
|
||||
func (t *timelineDB) GetPublicTimelineForAccount(accountID string, maxID string, sinceID string, minID string, limit int, local bool) ([]*gtsmodel.Status, db.Error) {
|
||||
func (t *timelineDB) GetPublicTimeline(accountID string, maxID string, sinceID string, minID string, limit int, local bool) ([]*gtsmodel.Status, db.Error) {
|
||||
statuses := []*gtsmodel.Status{}
|
||||
|
||||
q := t.conn.Model(&statuses).
|
||||
|
|
@ -143,7 +143,7 @@ func (t *timelineDB) GetPublicTimelineForAccount(accountID string, maxID string,
|
|||
|
||||
// TODO optimize this query and the logic here, because it's slow as balls -- it takes like a literal second to return with a limit of 20!
|
||||
// It might be worth serving it through a timeline instead of raw DB queries, like we do for Home feeds.
|
||||
func (t *timelineDB) GetFavedTimelineForAccount(accountID string, maxID string, minID string, limit int) ([]*gtsmodel.Status, string, string, db.Error) {
|
||||
func (t *timelineDB) GetFavedTimeline(accountID string, maxID string, minID string, limit int) ([]*gtsmodel.Status, string, string, db.Error) {
|
||||
|
||||
faves := []*gtsmodel.StatusFave{}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue