diff options
author | 2024-04-16 13:10:13 +0200 | |
---|---|---|
committer | 2024-04-16 13:10:13 +0200 | |
commit | 3cceed11b28b5f42a653d85ed779d652fd8c26ad (patch) | |
tree | 0a7f0994e477609ca705a45f382dfb62056b196e /internal/db/account.go | |
parent | [performance] cached oauth database types (#2838) (diff) | |
download | gotosocial-3cceed11b28b5f42a653d85ed779d652fd8c26ad.tar.xz |
[feature/performance] Store account stats in separate table (#2831)
* [feature/performance] Store account stats in separate table, get stats from remote
* test account stats
* add some missing increment / decrement calls
* change stats function signatures
* rejig logging a bit
* use lock when updating stats
Diffstat (limited to 'internal/db/account.go')
-rw-r--r-- | internal/db/account.go | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/internal/db/account.go b/internal/db/account.go index 7cdf7b57f..dec36d2ac 100644 --- a/internal/db/account.go +++ b/internal/db/account.go @@ -20,7 +20,6 @@ package db import ( "context" "net/netip" - "time" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/paging" @@ -100,12 +99,6 @@ type Account interface { // GetAccountsUsingEmoji fetches all account models using emoji with given ID stored in their 'emojis' column. GetAccountsUsingEmoji(ctx context.Context, emojiID string) ([]*gtsmodel.Account, error) - // GetAccountStatusesCount is a shortcut for the common action of counting statuses produced by accountID. - CountAccountStatuses(ctx context.Context, accountID string) (int, error) - - // CountAccountPinned returns the total number of pinned statuses owned by account with the given id. - CountAccountPinned(ctx context.Context, accountID string) (int, error) - // GetAccountStatuses is a shortcut for getting the most recent statuses. accountID is optional, if not provided // then all statuses will be returned. If limit is set to 0, the size of the returned slice will not be limited. This can // be very memory intensive so you probably shouldn't do this! @@ -128,13 +121,6 @@ type Account interface { // In the case of no statuses, this function will return db.ErrNoEntries. GetAccountWebStatuses(ctx context.Context, accountID string, limit int, maxID string) ([]*gtsmodel.Status, error) - // GetAccountLastPosted simply gets the timestamp of the most recent post by the account. - // - // If webOnly is true, then the time of the last non-reply, non-boost, public status of the account will be returned. - // - // The returned time will be zero if account has never posted anything. - GetAccountLastPosted(ctx context.Context, accountID string, webOnly bool) (time.Time, error) - // SetAccountHeaderOrAvatar sets the header or avatar for the given accountID to the given media attachment. SetAccountHeaderOrAvatar(ctx context.Context, mediaAttachment *gtsmodel.MediaAttachment, accountID string) error @@ -150,4 +136,24 @@ type Account interface { // Update local account settings. UpdateAccountSettings(ctx context.Context, settings *gtsmodel.AccountSettings, columns ...string) error + + // PopulateAccountStats gets (or creates and gets) account stats for + // the given account, and attaches them to the account model. + PopulateAccountStats(ctx context.Context, account *gtsmodel.Account) error + + // RegenerateAccountStats creates, upserts, and returns stats + // for the given account, and attaches them to the account model. + // + // Unlike GetAccountStats, it will always get the database stats fresh. + // This can be used to "refresh" stats. + // + // Because this involves database calls that can be expensive (on Postgres + // specifically), callers should prefer GetAccountStats in 99% of cases. + RegenerateAccountStats(ctx context.Context, account *gtsmodel.Account) error + + // Update account stats. + UpdateAccountStats(ctx context.Context, stats *gtsmodel.AccountStats, columns ...string) error + + // DeleteAccountStats deletes the accountStats entry for the given accountID. + DeleteAccountStats(ctx context.Context, accountID string) error } |