diff options
| author | 2024-08-02 12:15:11 +0000 | |
|---|---|---|
| committer | 2024-08-02 13:15:11 +0100 | |
| commit | 0f734a24100383171a866fccc194dea578141d74 (patch) | |
| tree | a2cfdebeb1098ef39a8b2907a0933ac7f18a3ca3 /internal/processing | |
| parent | [chore] add back exif-terminator and use only for jpeg,png,webp (#3161) (diff) | |
| download | gotosocial-0f734a24100383171a866fccc194dea578141d74.tar.xz | |
[chore] move PopulateAccountStats() nil check often performed into function itself (#3158)
* move PopulateAccountStats() nil check often performed into function itself
* fix test to take in mind we don't repopulate account stats if not-nil
Diffstat (limited to 'internal/processing')
| -rw-r--r-- | internal/processing/account/rss.go | 8 | ||||
| -rw-r--r-- | internal/processing/fedi/collections.go | 24 | ||||
| -rw-r--r-- | internal/processing/status/pin.go | 16 | ||||
| -rw-r--r-- | internal/processing/workers/util.go | 48 | 
4 files changed, 34 insertions, 62 deletions
| diff --git a/internal/processing/account/rss.go b/internal/processing/account/rss.go index cbbb4875b..60f93b012 100644 --- a/internal/processing/account/rss.go +++ b/internal/processing/account/rss.go @@ -70,11 +70,9 @@ func (p *Processor) GetRSSFeedForUsername(ctx context.Context, username string)  	}  	// Ensure account stats populated. -	if account.Stats == nil { -		if err := p.state.DB.PopulateAccountStats(ctx, account); err != nil { -			err = gtserror.Newf("db error getting account stats %s: %w", username, err) -			return nil, never, gtserror.NewErrorInternalError(err) -		} +	if err := p.state.DB.PopulateAccountStats(ctx, account); err != nil { +		err = gtserror.Newf("db error getting account stats %s: %w", username, err) +		return nil, never, gtserror.NewErrorInternalError(err)  	}  	// LastModified time is needed by callers to check freshness for cacheing. diff --git a/internal/processing/fedi/collections.go b/internal/processing/fedi/collections.go index a1fc5e1f4..e81d3e269 100644 --- a/internal/processing/fedi/collections.go +++ b/internal/processing/fedi/collections.go @@ -70,11 +70,9 @@ func (p *Processor) OutboxGet(  	}  	// Ensure we have stats for this account. -	if receivingAcct.Stats == nil { -		if err := p.state.DB.PopulateAccountStats(ctx, receivingAcct); err != nil { -			err := gtserror.Newf("error getting stats for account %s: %w", receivingAcct.ID, err) -			return nil, gtserror.NewErrorInternalError(err) -		} +	if err := p.state.DB.PopulateAccountStats(ctx, receivingAcct); err != nil { +		err := gtserror.Newf("error getting stats for account %s: %w", receivingAcct.ID, err) +		return nil, gtserror.NewErrorInternalError(err)  	}  	var obj vocab.Type @@ -200,11 +198,9 @@ func (p *Processor) FollowersGet(  	}  	// Ensure we have stats for this account. -	if receivingAcct.Stats == nil { -		if err := p.state.DB.PopulateAccountStats(ctx, receivingAcct); err != nil { -			err := gtserror.Newf("error getting stats for account %s: %w", receivingAcct.ID, err) -			return nil, gtserror.NewErrorInternalError(err) -		} +	if err := p.state.DB.PopulateAccountStats(ctx, receivingAcct); err != nil { +		err := gtserror.Newf("error getting stats for account %s: %w", receivingAcct.ID, err) +		return nil, gtserror.NewErrorInternalError(err)  	}  	var obj vocab.Type @@ -314,11 +310,9 @@ func (p *Processor) FollowingGet(ctx context.Context, requestedUser string, page  	}  	// Ensure we have stats for this account. -	if receivingAcct.Stats == nil { -		if err := p.state.DB.PopulateAccountStats(ctx, receivingAcct); err != nil { -			err := gtserror.Newf("error getting stats for account %s: %w", receivingAcct.ID, err) -			return nil, gtserror.NewErrorInternalError(err) -		} +	if err := p.state.DB.PopulateAccountStats(ctx, receivingAcct); err != nil { +		err := gtserror.Newf("error getting stats for account %s: %w", receivingAcct.ID, err) +		return nil, gtserror.NewErrorInternalError(err)  	}  	var obj vocab.Type diff --git a/internal/processing/status/pin.go b/internal/processing/status/pin.go index c4a6fc3b8..3f8435e52 100644 --- a/internal/processing/status/pin.go +++ b/internal/processing/status/pin.go @@ -92,11 +92,9 @@ func (p *Processor) PinCreate(ctx context.Context, requestingAccount *gtsmodel.A  	}  	// Ensure account stats populated. -	if requestingAccount.Stats == nil { -		if err := p.state.DB.PopulateAccountStats(ctx, requestingAccount); err != nil { -			err = gtserror.Newf("db error getting account stats: %w", err) -			return nil, gtserror.NewErrorInternalError(err) -		} +	if err := p.state.DB.PopulateAccountStats(ctx, requestingAccount); err != nil { +		err = gtserror.Newf("db error getting account stats: %w", err) +		return nil, gtserror.NewErrorInternalError(err)  	}  	pinnedCount := *requestingAccount.Stats.StatusesPinnedCount @@ -157,11 +155,9 @@ func (p *Processor) PinRemove(ctx context.Context, requestingAccount *gtsmodel.A  	}  	// Ensure account stats populated. -	if requestingAccount.Stats == nil { -		if err := p.state.DB.PopulateAccountStats(ctx, requestingAccount); err != nil { -			err = gtserror.Newf("db error getting account stats: %w", err) -			return nil, gtserror.NewErrorInternalError(err) -		} +	if err := p.state.DB.PopulateAccountStats(ctx, requestingAccount); err != nil { +		err = gtserror.Newf("db error getting account stats: %w", err) +		return nil, gtserror.NewErrorInternalError(err)  	}  	targetStatus.PinnedAt = time.Time{} diff --git a/internal/processing/workers/util.go b/internal/processing/workers/util.go index 994242d37..7f6c259de 100644 --- a/internal/processing/workers/util.go +++ b/internal/processing/workers/util.go @@ -257,10 +257,8 @@ func (u *utils) incrementStatusesCount(  	defer unlock()  	// Populate stats. -	if account.Stats == nil { -		if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil { -			return gtserror.Newf("db error getting account stats: %w", err) -		} +	if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil { +		return gtserror.Newf("db error getting account stats: %w", err)  	}  	// Update stats by incrementing status @@ -288,10 +286,8 @@ func (u *utils) decrementStatusesCount(  	defer unlock()  	// Populate stats. -	if account.Stats == nil { -		if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil { -			return gtserror.Newf("db error getting account stats: %w", err) -		} +	if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil { +		return gtserror.Newf("db error getting account stats: %w", err)  	}  	// Update stats by decrementing @@ -322,10 +318,8 @@ func (u *utils) incrementFollowersCount(  	defer unlock()  	// Populate stats. -	if account.Stats == nil { -		if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil { -			return gtserror.Newf("db error getting account stats: %w", err) -		} +	if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil { +		return gtserror.Newf("db error getting account stats: %w", err)  	}  	// Update stats by incrementing followers @@ -351,10 +345,8 @@ func (u *utils) decrementFollowersCount(  	defer unlock()  	// Populate stats. -	if account.Stats == nil { -		if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil { -			return gtserror.Newf("db error getting account stats: %w", err) -		} +	if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil { +		return gtserror.Newf("db error getting account stats: %w", err)  	}  	// Update stats by decrementing @@ -385,10 +377,8 @@ func (u *utils) incrementFollowingCount(  	defer unlock()  	// Populate stats. -	if account.Stats == nil { -		if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil { -			return gtserror.Newf("db error getting account stats: %w", err) -		} +	if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil { +		return gtserror.Newf("db error getting account stats: %w", err)  	}  	// Update stats by incrementing @@ -414,10 +404,8 @@ func (u *utils) decrementFollowingCount(  	defer unlock()  	// Populate stats. -	if account.Stats == nil { -		if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil { -			return gtserror.Newf("db error getting account stats: %w", err) -		} +	if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil { +		return gtserror.Newf("db error getting account stats: %w", err)  	}  	// Update stats by decrementing @@ -448,10 +436,8 @@ func (u *utils) incrementFollowRequestsCount(  	defer unlock()  	// Populate stats. -	if account.Stats == nil { -		if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil { -			return gtserror.Newf("db error getting account stats: %w", err) -		} +	if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil { +		return gtserror.Newf("db error getting account stats: %w", err)  	}  	// Update stats by incrementing @@ -477,10 +463,8 @@ func (u *utils) decrementFollowRequestsCount(  	defer unlock()  	// Populate stats. -	if account.Stats == nil { -		if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil { -			return gtserror.Newf("db error getting account stats: %w", err) -		} +	if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil { +		return gtserror.Newf("db error getting account stats: %w", err)  	}  	// Update stats by decrementing | 
