[feature] Add instance-stats-randomize config option (#3718)

* [feature] Add `instance-stats-randomize` config option

* don't use cache (overkill)
This commit is contained in:
tobi
2025-01-31 19:27:18 +01:00
committed by GitHub
parent c47b9bd1d1
commit a55bd6d2bd
13 changed files with 183 additions and 10 deletions

View File

@@ -65,16 +65,30 @@ func (p *Processor) NodeInfoRelGet(ctx context.Context) (*apimodel.WellKnownResp
// NodeInfoGet returns a node info struct in response to a node info request.
func (p *Processor) NodeInfoGet(ctx context.Context) (*apimodel.Nodeinfo, gtserror.WithCode) {
host := config.GetHost()
var (
userCount int
postCount int
err error
)
userCount, err := p.state.DB.CountInstanceUsers(ctx, host)
if err != nil {
return nil, gtserror.NewErrorInternalError(err)
}
if config.GetInstanceStatsRandomize() {
// Use randomized stats.
stats := p.converter.RandomStats()
userCount = int(stats.TotalUsers)
postCount = int(stats.Statuses)
} else {
// Count actual stats.
host := config.GetHost()
postCount, err := p.state.DB.CountInstanceStatuses(ctx, host)
if err != nil {
return nil, gtserror.NewErrorInternalError(err)
userCount, err = p.state.DB.CountInstanceUsers(ctx, host)
if err != nil {
return nil, gtserror.NewErrorInternalError(err)
}
postCount, err = p.state.DB.CountInstanceStatuses(ctx, host)
if err != nil {
return nil, gtserror.NewErrorInternalError(err)
}
}
return &apimodel.Nodeinfo{