MM-43918: freemium limit for storage (#20225)
Summary Adds an API end point to return storage usage Ticket Link https://mattermost.atlassian.net/browse/MM-43918
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
1f6e2fe846
Коммит
8f912b697e
@@ -191,7 +191,8 @@ type AppIface interface {
|
||||
// To get the plugins environment when the plugins are disabled, manually acquire the plugins
|
||||
// lock instead.
|
||||
GetPluginsEnvironment() *plugin.Environment
|
||||
// GetPostsUsage returns "rounded off" total posts count like returns 900 instead of 987
|
||||
// GetPostsUsage returns the total posts count rounded down to the most
|
||||
// significant digit
|
||||
GetPostsUsage() (int64, *model.AppError)
|
||||
// GetProductNotices is called from the frontend to fetch the product notices that are relevant to the caller
|
||||
GetProductNotices(c *request.Context, userID, teamID string, client model.NoticeClientType, clientVersion string, locale string) (model.NoticeMessages, *model.AppError)
|
||||
@@ -204,6 +205,8 @@ type AppIface interface {
|
||||
// GetSessionLengthInMillis returns the session length, in milliseconds,
|
||||
// based on the type of session (Mobile, SSO, Web/LDAP).
|
||||
GetSessionLengthInMillis(session *model.Session) int64
|
||||
// GetStorageUsage returns the sum of files' sizes stored on this instance
|
||||
GetStorageUsage() (int64, *model.AppError)
|
||||
// GetSuggestions returns suggestions for user input.
|
||||
GetSuggestions(c *request.Context, commandArgs *model.CommandArgs, commands []*model.Command, roleID string) []model.AutocompleteSuggestion
|
||||
// GetTeamGroupUsers returns the users who are associated to the team via GroupTeams and GroupMembers.
|
||||
|
||||
@@ -9095,6 +9095,28 @@ func (a *OpenTracingAppLayer) GetStatusesByIds(userIDs []string) (map[string]int
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetStorageUsage() (int64, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetStorageUsage")
|
||||
|
||||
a.ctx = newCtx
|
||||
a.app.Srv().Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
a.app.Srv().Store.SetContext(origCtx)
|
||||
a.ctx = origCtx
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetStorageUsage()
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetSuggestions(c *request.Context, commandArgs *model.CommandArgs, commands []*model.Command, roleID string) []model.AutocompleteSuggestion {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetSuggestions")
|
||||
|
||||
13
app/usage.go
13
app/usage.go
@@ -45,7 +45,8 @@ func (ch *Channels) getIntegrationsUsage() (*model.IntegrationsUsage, *model.App
|
||||
return &model.IntegrationsUsage{Enabled: count}, nil
|
||||
}
|
||||
|
||||
// GetPostsUsage returns "rounded off" total posts count like returns 900 instead of 987
|
||||
// GetPostsUsage returns the total posts count rounded down to the most
|
||||
// significant digit
|
||||
func (a *App) GetPostsUsage() (int64, *model.AppError) {
|
||||
count, err := a.Srv().Store.Post().AnalyticsPostCount(&model.PostCountOptions{ExcludeDeleted: true, UsersPostsOnly: true, AllowFromCache: true})
|
||||
if err != nil {
|
||||
@@ -55,6 +56,15 @@ func (a *App) GetPostsUsage() (int64, *model.AppError) {
|
||||
return utils.RoundOffToZeroes(float64(count)), nil
|
||||
}
|
||||
|
||||
// GetStorageUsage returns the sum of files' sizes stored on this instance
|
||||
func (a *App) GetStorageUsage() (int64, *model.AppError) {
|
||||
usage, err := a.Srv().Store.FileInfo().GetStorageUsage(true, false)
|
||||
if err != nil {
|
||||
return 0, model.NewAppError("GetStorageUsage", "app.usage.get_storage_usage.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return usage, nil
|
||||
}
|
||||
|
||||
func (a *App) GetTeamsUsage() (*model.TeamsUsage, *model.AppError) {
|
||||
usage := &model.TeamsUsage{}
|
||||
includeDeleted := false
|
||||
@@ -79,6 +89,5 @@ func (a *App) GetTeamsUsage() (*model.TeamsUsage, *model.AppError) {
|
||||
}
|
||||
|
||||
usage.CloudArchived = int64(cloudArchivedTeamCount)
|
||||
|
||||
return usage, nil
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user