diff options
Diffstat (limited to 'internal/db/bundb/account.go')
-rw-r--r-- | internal/db/bundb/account.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/internal/db/bundb/account.go b/internal/db/bundb/account.go index eb5385c70..43978243a 100644 --- a/internal/db/bundb/account.go +++ b/internal/db/bundb/account.go @@ -1217,6 +1217,35 @@ func (a *accountDB) PopulateAccountStats(ctx context.Context, account *gtsmodel. return nil } +func (a *accountDB) StubAccountStats(ctx context.Context, account *gtsmodel.Account) error { + stats := >smodel.AccountStats{ + AccountID: account.ID, + RegeneratedAt: time.Now(), + FollowersCount: util.Ptr(0), + FollowingCount: util.Ptr(0), + FollowRequestsCount: util.Ptr(0), + StatusesCount: util.Ptr(0), + StatusesPinnedCount: util.Ptr(0), + } + + // Upsert this stats in case a race + // meant someone else inserted it first. + if err := a.state.Caches.GTS.AccountStats.Store(stats, func() error { + if _, err := NewUpsert(a.db). + Model(stats). + Constraint("account_id"). + Exec(ctx); err != nil { + return err + } + return nil + }); err != nil { + return err + } + + account.Stats = stats + return nil +} + func (a *accountDB) RegenerateAccountStats(ctx context.Context, account *gtsmodel.Account) error { // Initialize a new stats struct. stats := >smodel.AccountStats{ |