mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-05-31 22:58:32 +00:00
use lock when updating stats
This commit is contained in:
parent
9d15127841
commit
ceb84e55ee
|
@ -113,7 +113,7 @@ func (p *Processor) MoveSelf(
|
|||
// in quick succession, so get a lock on
|
||||
// this account.
|
||||
lockKey := originAcct.URI
|
||||
unlock := p.state.ClientLocks.Lock(lockKey)
|
||||
unlock := p.state.AccountLocks.Lock(lockKey)
|
||||
defer unlock()
|
||||
|
||||
// Ensure we have a valid, up-to-date representation of the target account.
|
||||
|
|
|
@ -49,7 +49,7 @@ func (p *Processor) AccountApprove(
|
|||
// Get a lock on the account URI,
|
||||
// to ensure it's not also being
|
||||
// rejected at the same time!
|
||||
unlock := p.state.ClientLocks.Lock(user.Account.URI)
|
||||
unlock := p.state.AccountLocks.Lock(user.Account.URI)
|
||||
defer unlock()
|
||||
|
||||
if !*user.Approved {
|
||||
|
|
|
@ -52,7 +52,7 @@ func (p *Processor) AccountReject(
|
|||
// Get a lock on the account URI,
|
||||
// since we're going to be deleting
|
||||
// it and its associated user.
|
||||
unlock := p.state.ClientLocks.Lock(user.Account.URI)
|
||||
unlock := p.state.AccountLocks.Lock(user.Account.URI)
|
||||
defer unlock()
|
||||
|
||||
// Can't reject an account with a
|
||||
|
|
|
@ -83,7 +83,7 @@ func (p *Processor) PinCreate(ctx context.Context, requestingAccount *gtsmodel.A
|
|||
}
|
||||
|
||||
// Get a lock on this account.
|
||||
unlock := p.state.ClientLocks.Lock(requestingAccount.URI)
|
||||
unlock := p.state.AccountLocks.Lock(requestingAccount.URI)
|
||||
defer unlock()
|
||||
|
||||
if !targetStatus.PinnedAt.IsZero() {
|
||||
|
@ -148,7 +148,7 @@ func (p *Processor) PinRemove(ctx context.Context, requestingAccount *gtsmodel.A
|
|||
}
|
||||
|
||||
// Get a lock on this account.
|
||||
unlock := p.state.ClientLocks.Lock(requestingAccount.URI)
|
||||
unlock := p.state.AccountLocks.Lock(requestingAccount.URI)
|
||||
defer unlock()
|
||||
|
||||
if targetStatus.PinnedAt.IsZero() {
|
||||
|
|
|
@ -244,6 +244,10 @@ func (u *utilF) incrementStatusesCount(
|
|||
account *gtsmodel.Account,
|
||||
status *gtsmodel.Status,
|
||||
) error {
|
||||
// Lock on this account since we're changing stats.
|
||||
unlock := u.state.AccountLocks.Lock(account.URI)
|
||||
defer unlock()
|
||||
|
||||
// Populate stats.
|
||||
if account.Stats == nil {
|
||||
if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil {
|
||||
|
@ -271,6 +275,10 @@ func (u *utilF) decrementStatusesCount(
|
|||
ctx context.Context,
|
||||
account *gtsmodel.Account,
|
||||
) error {
|
||||
// Lock on this account since we're changing stats.
|
||||
unlock := u.state.AccountLocks.Lock(account.URI)
|
||||
defer unlock()
|
||||
|
||||
// Populate stats.
|
||||
if account.Stats == nil {
|
||||
if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil {
|
||||
|
@ -301,6 +309,10 @@ func (u *utilF) incrementFollowersCount(
|
|||
ctx context.Context,
|
||||
account *gtsmodel.Account,
|
||||
) error {
|
||||
// Lock on this account since we're changing stats.
|
||||
unlock := u.state.AccountLocks.Lock(account.URI)
|
||||
defer unlock()
|
||||
|
||||
// Populate stats.
|
||||
if account.Stats == nil {
|
||||
if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil {
|
||||
|
@ -326,6 +338,10 @@ func (u *utilF) decrementFollowersCount(
|
|||
ctx context.Context,
|
||||
account *gtsmodel.Account,
|
||||
) error {
|
||||
// Lock on this account since we're changing stats.
|
||||
unlock := u.state.AccountLocks.Lock(account.URI)
|
||||
defer unlock()
|
||||
|
||||
// Populate stats.
|
||||
if account.Stats == nil {
|
||||
if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil {
|
||||
|
@ -356,6 +372,10 @@ func (u *utilF) incrementFollowingCount(
|
|||
ctx context.Context,
|
||||
account *gtsmodel.Account,
|
||||
) error {
|
||||
// Lock on this account since we're changing stats.
|
||||
unlock := u.state.AccountLocks.Lock(account.URI)
|
||||
defer unlock()
|
||||
|
||||
// Populate stats.
|
||||
if account.Stats == nil {
|
||||
if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil {
|
||||
|
@ -381,6 +401,10 @@ func (u *utilF) decrementFollowingCount(
|
|||
ctx context.Context,
|
||||
account *gtsmodel.Account,
|
||||
) error {
|
||||
// Lock on this account since we're changing stats.
|
||||
unlock := u.state.AccountLocks.Lock(account.URI)
|
||||
defer unlock()
|
||||
|
||||
// Populate stats.
|
||||
if account.Stats == nil {
|
||||
if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil {
|
||||
|
@ -411,6 +435,10 @@ func (u *utilF) incrementFollowRequestsCount(
|
|||
ctx context.Context,
|
||||
account *gtsmodel.Account,
|
||||
) error {
|
||||
// Lock on this account since we're changing stats.
|
||||
unlock := u.state.AccountLocks.Lock(account.URI)
|
||||
defer unlock()
|
||||
|
||||
// Populate stats.
|
||||
if account.Stats == nil {
|
||||
if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil {
|
||||
|
@ -436,6 +464,10 @@ func (u *utilF) decrementFollowRequestsCount(
|
|||
ctx context.Context,
|
||||
account *gtsmodel.Account,
|
||||
) error {
|
||||
// Lock on this account since we're changing stats.
|
||||
unlock := u.state.AccountLocks.Lock(account.URI)
|
||||
defer unlock()
|
||||
|
||||
// Populate stats.
|
||||
if account.Stats == nil {
|
||||
if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil {
|
||||
|
|
|
@ -50,11 +50,12 @@ type State struct {
|
|||
// functions, and by the go-fed/activity library.
|
||||
FedLocks mutexes.MutexMap
|
||||
|
||||
// ClientLocks provides access to this state's
|
||||
// mutex map of per URI client locks.
|
||||
//
|
||||
// Used during account migration actions.
|
||||
ClientLocks mutexes.MutexMap
|
||||
// AccountLocks provides access to this state's
|
||||
// mutex map of per URI locks, intended for use
|
||||
// when updating accounts, migrating, approving
|
||||
// or rejecting an account, changing stats,
|
||||
// pinned statuses, etc.
|
||||
AccountLocks mutexes.MutexMap
|
||||
|
||||
// Storage provides access to the storage driver.
|
||||
Storage *storage.Driver
|
||||
|
|
Loading…
Reference in a new issue