mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 13:22:25 -05:00
[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:
parent
c47b9bd1d1
commit
a55bd6d2bd
13 changed files with 183 additions and 10 deletions
|
|
@ -21,7 +21,9 @@ import (
|
|||
"net/http"
|
||||
|
||||
apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/util"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
|
@ -58,6 +60,12 @@ func (m *Module) InstanceInformationGETHandlerV1(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if config.GetInstanceStatsRandomize() {
|
||||
// Replace actual stats with cached randomized ones.
|
||||
instance.Stats["user_count"] = util.Ptr(int(instance.RandomStats.TotalUsers))
|
||||
instance.Stats["status_count"] = util.Ptr(int(instance.RandomStats.Statuses))
|
||||
}
|
||||
|
||||
apiutil.JSON(c, http.StatusOK, instance)
|
||||
}
|
||||
|
||||
|
|
@ -93,5 +101,10 @@ func (m *Module) InstanceInformationGETHandlerV2(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if config.GetInstanceStatsRandomize() {
|
||||
// Replace actual stats with cached randomized ones.
|
||||
instance.Usage.Users.ActiveMonth = int(instance.RandomStats.MonthlyActiveUsers)
|
||||
}
|
||||
|
||||
apiutil.JSON(c, http.StatusOK, instance)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,10 @@
|
|||
|
||||
package model
|
||||
|
||||
import "mime/multipart"
|
||||
import (
|
||||
"mime/multipart"
|
||||
"time"
|
||||
)
|
||||
|
||||
// InstanceSettingsUpdateRequest models an instance update request.
|
||||
//
|
||||
|
|
@ -148,3 +151,11 @@ type InstanceConfigurationEmojis struct {
|
|||
// example: 51200
|
||||
EmojiSizeLimit int `json:"emoji_size_limit"`
|
||||
}
|
||||
|
||||
// swagger:ignore
|
||||
type RandomStats struct {
|
||||
Statuses int64
|
||||
TotalUsers int64
|
||||
MonthlyActiveUsers int64
|
||||
Generated time.Time
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,6 +110,13 @@ type InstanceV1 struct {
|
|||
Terms string `json:"terms,omitempty"`
|
||||
// Raw (unparsed) version of terms.
|
||||
TermsRaw string `json:"terms_text,omitempty"`
|
||||
|
||||
// Random stats generated for the instance.
|
||||
// Only used if `instance-stats-randomize` is true.
|
||||
// Not serialized to the frontend.
|
||||
//
|
||||
// swagger:ignore
|
||||
RandomStats `json:"-"`
|
||||
}
|
||||
|
||||
// InstanceV1URLs models instance-relevant URLs for client application consumption.
|
||||
|
|
|
|||
|
|
@ -74,6 +74,13 @@ type InstanceV2 struct {
|
|||
Terms string `json:"terms,omitempty"`
|
||||
// Raw (unparsed) version of terms.
|
||||
TermsText string `json:"terms_text,omitempty"`
|
||||
|
||||
// Random stats generated for the instance.
|
||||
// Only used if `instance-stats-randomize` is true.
|
||||
// Not serialized to the frontend.
|
||||
//
|
||||
// swagger:ignore
|
||||
RandomStats `json:"-"`
|
||||
}
|
||||
|
||||
// Usage data for this instance.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue