mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 03:22:24 -05:00
[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
This commit is contained in:
parent
f79d50b9b2
commit
3cceed11b2
43 changed files with 1285 additions and 450 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue