diff --git a/server/channels/api4/system.go b/server/channels/api4/system.go index 2a5886a6ec..6396d1963a 100644 --- a/server/channels/api4/system.go +++ b/server/channels/api4/system.go @@ -463,7 +463,7 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) { return } - rows, appErr := c.App.GetAnalytics(name, teamId) + rows, appErr := c.App.GetAnalytics(c.AppContext, name, teamId) if appErr != nil { c.Err = appErr return diff --git a/server/channels/api4/user.go b/server/channels/api4/user.go index b0b012da33..472d0c0100 100644 --- a/server/channels/api4/user.go +++ b/server/channels/api4/user.go @@ -851,9 +851,9 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) { } if sort == "last_activity_at" { - profiles, appErr = c.App.GetRecentlyActiveUsersForTeamPage(inTeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), restrictions) + profiles, appErr = c.App.GetRecentlyActiveUsersForTeamPage(c.AppContext, inTeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), restrictions) } else if sort == "create_at" { - profiles, appErr = c.App.GetNewUsersForTeamPage(inTeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), restrictions) + profiles, appErr = c.App.GetNewUsersForTeamPage(c.AppContext, inTeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), restrictions) } else { etag = c.App.GetUsersInTeamEtag(inTeamId, restrictions.Hash()) if c.HandleEtag(etag, "Get Users in Team", w, r) { diff --git a/server/channels/api4/user_local.go b/server/channels/api4/user_local.go index 1bd00b82a2..d56911ab36 100644 --- a/server/channels/api4/user_local.go +++ b/server/channels/api4/user_local.go @@ -194,9 +194,9 @@ func localGetUsers(c *Context, w http.ResponseWriter, r *http.Request) { profiles, appErr = c.App.GetUsersNotInTeamPage(notInTeamId, groupConstrainedBool, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), nil) } else if inTeamId != "" { if sort == "last_activity_at" { - profiles, appErr = c.App.GetRecentlyActiveUsersForTeamPage(inTeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), nil) + profiles, appErr = c.App.GetRecentlyActiveUsersForTeamPage(c.AppContext, c.Params.TeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), nil) } else if sort == "create_at" { - profiles, appErr = c.App.GetNewUsersForTeamPage(inTeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), nil) + profiles, appErr = c.App.GetNewUsersForTeamPage(c.AppContext, c.Params.TeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), nil) } else { etag = c.App.GetUsersInTeamEtag(inTeamId, "") if c.HandleEtag(etag, "Get Users in Team", w, r) { diff --git a/server/channels/app/analytics.go b/server/channels/app/analytics.go index 205bbeb753..0086b892db 100644 --- a/server/channels/app/analytics.go +++ b/server/channels/app/analytics.go @@ -10,6 +10,7 @@ import ( "github.com/mattermost/mattermost/server/public/model" "github.com/mattermost/mattermost/server/public/shared/mlog" + "github.com/mattermost/mattermost/server/public/shared/request" ) const ( @@ -17,7 +18,7 @@ const ( MonthMilliseconds = 31 * DayMilliseconds ) -func (a *App) GetAnalytics(name string, teamID string) (model.AnalyticsRows, *model.AppError) { +func (a *App) GetAnalytics(rctx request.CTX, name string, teamID string) (model.AnalyticsRows, *model.AppError) { skipIntensiveQueries := false var systemUserCount int64 systemUserCount, err := a.Srv().Store().User().Count(model.UserCountOptions{}) @@ -26,7 +27,7 @@ func (a *App) GetAnalytics(name string, teamID string) (model.AnalyticsRows, *mo } if systemUserCount > int64(*a.Config().AnalyticsSettings.MaxUsersForStatistics) { - mlog.Debug("More than limit users are on the system, intensive queries skipped", mlog.Int("limit", *a.Config().AnalyticsSettings.MaxUsersForStatistics)) + rctx.Logger().Debug("More than limit users are on the system, intensive queries skipped", mlog.Int("limit", *a.Config().AnalyticsSettings.MaxUsersForStatistics)) skipIntensiveQueries = true } @@ -306,7 +307,7 @@ func (a *App) GetAnalytics(name string, teamID string) (model.AnalyticsRows, *mo return nil, nil } -func (a *App) GetRecentlyActiveUsersForTeam(teamID string) (map[string]*model.User, *model.AppError) { +func (a *App) GetRecentlyActiveUsersForTeam(rctx request.CTX, teamID string) (map[string]*model.User, *model.AppError) { users, err := a.Srv().Store().User().GetRecentlyActiveUsersForTeam(teamID, 0, 100, nil) if err != nil { return nil, model.NewAppError("GetRecentlyActiveUsersForTeam", "app.user.get_recently_active_users.app_error", nil, "", http.StatusInternalServerError).Wrap(err) @@ -321,7 +322,7 @@ func (a *App) GetRecentlyActiveUsersForTeam(teamID string) (map[string]*model.Us return userMap, nil } -func (a *App) GetRecentlyActiveUsersForTeamPage(teamID string, page, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) { +func (a *App) GetRecentlyActiveUsersForTeamPage(rctx request.CTX, teamID string, page, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) { users, err := a.Srv().Store().User().GetRecentlyActiveUsersForTeam(teamID, page*perPage, perPage, viewRestrictions) if err != nil { return nil, model.NewAppError("GetRecentlyActiveUsersForTeamPage", "app.user.get_recently_active_users.app_error", nil, "", http.StatusInternalServerError).Wrap(err) @@ -330,7 +331,7 @@ func (a *App) GetRecentlyActiveUsersForTeamPage(teamID string, page, perPage int return a.sanitizeProfiles(users, asAdmin), nil } -func (a *App) GetNewUsersForTeamPage(teamID string, page, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) { +func (a *App) GetNewUsersForTeamPage(rctx request.CTX, teamID string, page, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) { users, err := a.Srv().Store().User().GetNewUsersForTeam(teamID, page*perPage, perPage, viewRestrictions) if err != nil { return nil, model.NewAppError("GetNewUsersForTeamPage", "app.user.get_new_users.app_error", nil, "", http.StatusInternalServerError).Wrap(err) diff --git a/server/channels/app/app_iface.go b/server/channels/app/app_iface.go index 57e8bf82fb..0ce3067835 100644 --- a/server/channels/app/app_iface.go +++ b/server/channels/app/app_iface.go @@ -621,7 +621,7 @@ type AppIface interface { GetAllTeams() ([]*model.Team, *model.AppError) GetAllTeamsPage(offset int, limit int, opts *model.TeamSearch) ([]*model.Team, *model.AppError) GetAllTeamsPageWithCount(offset int, limit int, opts *model.TeamSearch) (*model.TeamsWithCount, *model.AppError) - GetAnalytics(name string, teamID string) (model.AnalyticsRows, *model.AppError) + GetAnalytics(rctx request.CTX, name string, teamID string) (model.AnalyticsRows, *model.AppError) GetAppliedSchemaMigrations() ([]model.AppliedMigration, *model.AppError) GetAudits(rctx request.CTX, userID string, limit int) (model.Audits, *model.AppError) GetAuditsPage(rctx request.CTX, userID string, page int, perPage int) (model.Audits, *model.AppError) @@ -717,7 +717,7 @@ type AppIface interface { GetMemberCountsByGroup(rctx request.CTX, channelID string, includeTimezones bool) ([]*model.ChannelMemberCountByGroup, *model.AppError) GetMessageForNotification(post *model.Post, teamName, siteUrl string, translateFunc i18n.TranslateFunc) string GetMultipleEmojiByName(c request.CTX, names []string) ([]*model.Emoji, *model.AppError) - GetNewUsersForTeamPage(teamID string, page, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) + GetNewUsersForTeamPage(rctx request.CTX, teamID string, page, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) GetNextPostIdFromPostList(postList *model.PostList, collapsedThreads bool) string GetNotificationNameFormat(user *model.User) string GetNumberOfChannelsOnTeam(c request.CTX, teamID string) (int, *model.AppError) @@ -771,8 +771,8 @@ type AppIface interface { GetPublicChannelsByIdsForTeam(c request.CTX, teamID string, channelIDs []string) (model.ChannelList, *model.AppError) GetPublicChannelsForTeam(c request.CTX, teamID string, offset int, limit int) (model.ChannelList, *model.AppError) GetReactionsForPost(postID string) ([]*model.Reaction, *model.AppError) - GetRecentlyActiveUsersForTeam(teamID string) (map[string]*model.User, *model.AppError) - GetRecentlyActiveUsersForTeamPage(teamID string, page, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) + GetRecentlyActiveUsersForTeam(rctx request.CTX, teamID string) (map[string]*model.User, *model.AppError) + GetRecentlyActiveUsersForTeamPage(rctx request.CTX, teamID string, page, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) GetRemoteCluster(remoteClusterId string) (*model.RemoteCluster, *model.AppError) GetRemoteClusterForUser(remoteID string, userID string) (*model.RemoteCluster, *model.AppError) GetRemoteClusterService() (remotecluster.RemoteClusterServiceIFace, *model.AppError) diff --git a/server/channels/app/opentracing/opentracing_layer.go b/server/channels/app/opentracing/opentracing_layer.go index 78bc11b6fd..3046efba75 100644 --- a/server/channels/app/opentracing/opentracing_layer.go +++ b/server/channels/app/opentracing/opentracing_layer.go @@ -5006,7 +5006,7 @@ func (a *OpenTracingAppLayer) GetAllTeamsPageWithCount(offset int, limit int, op return resultVar0, resultVar1 } -func (a *OpenTracingAppLayer) GetAnalytics(name string, teamID string) (model.AnalyticsRows, *model.AppError) { +func (a *OpenTracingAppLayer) GetAnalytics(rctx request.CTX, name string, teamID string) (model.AnalyticsRows, *model.AppError) { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetAnalytics") @@ -5018,7 +5018,7 @@ func (a *OpenTracingAppLayer) GetAnalytics(name string, teamID string) (model.An }() defer span.Finish() - resultVar0, resultVar1 := a.app.GetAnalytics(name, teamID) + resultVar0, resultVar1 := a.app.GetAnalytics(rctx, name, teamID) if resultVar1 != nil { span.LogFields(spanlog.Error(resultVar1)) @@ -7440,7 +7440,7 @@ func (a *OpenTracingAppLayer) GetMultipleEmojiByName(c request.CTX, names []stri return resultVar0, resultVar1 } -func (a *OpenTracingAppLayer) GetNewUsersForTeamPage(teamID string, page int, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) { +func (a *OpenTracingAppLayer) GetNewUsersForTeamPage(rctx request.CTX, teamID string, page int, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetNewUsersForTeamPage") @@ -7452,7 +7452,7 @@ func (a *OpenTracingAppLayer) GetNewUsersForTeamPage(teamID string, page int, pe }() defer span.Finish() - resultVar0, resultVar1 := a.app.GetNewUsersForTeamPage(teamID, page, perPage, asAdmin, viewRestrictions) + resultVar0, resultVar1 := a.app.GetNewUsersForTeamPage(rctx, teamID, page, perPage, asAdmin, viewRestrictions) if resultVar1 != nil { span.LogFields(spanlog.Error(resultVar1)) @@ -8779,7 +8779,7 @@ func (a *OpenTracingAppLayer) GetReactionsForPost(postID string) ([]*model.React return resultVar0, resultVar1 } -func (a *OpenTracingAppLayer) GetRecentlyActiveUsersForTeam(teamID string) (map[string]*model.User, *model.AppError) { +func (a *OpenTracingAppLayer) GetRecentlyActiveUsersForTeam(rctx request.CTX, teamID string) (map[string]*model.User, *model.AppError) { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetRecentlyActiveUsersForTeam") @@ -8791,7 +8791,7 @@ func (a *OpenTracingAppLayer) GetRecentlyActiveUsersForTeam(teamID string) (map[ }() defer span.Finish() - resultVar0, resultVar1 := a.app.GetRecentlyActiveUsersForTeam(teamID) + resultVar0, resultVar1 := a.app.GetRecentlyActiveUsersForTeam(rctx, teamID) if resultVar1 != nil { span.LogFields(spanlog.Error(resultVar1)) @@ -8801,7 +8801,7 @@ func (a *OpenTracingAppLayer) GetRecentlyActiveUsersForTeam(teamID string) (map[ return resultVar0, resultVar1 } -func (a *OpenTracingAppLayer) GetRecentlyActiveUsersForTeamPage(teamID string, page int, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) { +func (a *OpenTracingAppLayer) GetRecentlyActiveUsersForTeamPage(rctx request.CTX, teamID string, page int, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetRecentlyActiveUsersForTeamPage") @@ -8813,7 +8813,7 @@ func (a *OpenTracingAppLayer) GetRecentlyActiveUsersForTeamPage(teamID string, p }() defer span.Finish() - resultVar0, resultVar1 := a.app.GetRecentlyActiveUsersForTeamPage(teamID, page, perPage, asAdmin, viewRestrictions) + resultVar0, resultVar1 := a.app.GetRecentlyActiveUsersForTeamPage(rctx, teamID, page, perPage, asAdmin, viewRestrictions) if resultVar1 != nil { span.LogFields(spanlog.Error(resultVar1)) diff --git a/server/channels/app/support_packet.go b/server/channels/app/support_packet.go index 82669f224c..ef00e661aa 100644 --- a/server/channels/app/support_packet.go +++ b/server/channels/app/support_packet.go @@ -203,7 +203,7 @@ func (a *App) generateSupportPacketYaml(c request.CTX) (*model.FileData, error) /* Server stats */ - analytics, appErr := a.GetAnalytics("standard", "") + analytics, appErr := a.GetAnalytics(c, "standard", "") if appErr != nil { rErr = multierror.Append(errors.Wrap(appErr, "error while getting analytics")) } diff --git a/server/channels/app/user_viewmembers_test.go b/server/channels/app/user_viewmembers_test.go index ddf0052a5e..93e8df2ad6 100644 --- a/server/channels/app/user_viewmembers_test.go +++ b/server/channels/app/user_viewmembers_test.go @@ -442,7 +442,7 @@ func TestRestrictedViewMembers(t *testing.T) { for _, tc := range testCases { t.Run(tc.Name, func(t *testing.T) { - results, err := th.App.GetNewUsersForTeamPage(tc.TeamId, 0, 2, false, tc.Restrictions) + results, err := th.App.GetNewUsersForTeamPage(th.Context, tc.TeamId, 0, 2, false, tc.Restrictions) require.Nil(t, err) ids := []string{} for _, result := range results { @@ -517,7 +517,7 @@ func TestRestrictedViewMembers(t *testing.T) { for _, tc := range testCases { t.Run(tc.Name, func(t *testing.T) { - results, err := th.App.GetRecentlyActiveUsersForTeamPage(tc.TeamId, 0, 3, false, tc.Restrictions) + results, err := th.App.GetRecentlyActiveUsersForTeamPage(th.Context, tc.TeamId, 0, 3, false, tc.Restrictions) require.Nil(t, err) ids := []string{} for _, result := range results { @@ -525,7 +525,7 @@ func TestRestrictedViewMembers(t *testing.T) { } assert.ElementsMatch(t, tc.ExpectedResults, ids) - results, err = th.App.GetRecentlyActiveUsersForTeamPage(tc.TeamId, 0, 1, false, tc.Restrictions) + results, err = th.App.GetRecentlyActiveUsersForTeamPage(th.Context, tc.TeamId, 0, 1, false, tc.Restrictions) require.Nil(t, err) if len(tc.ExpectedResults) > 1 { assert.Len(t, results, 1)