mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
MM-20305: Adds ability to choose whether deleted teams are included in the count query. (#13181)
This commit is contained in:
@@ -84,7 +84,7 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
||||
|
||||
teamCountChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
teamCount, err := a.Srv.Store.Team().AnalyticsTeamCount()
|
||||
teamCount, err := a.Srv.Store.Team().AnalyticsTeamCount(false)
|
||||
teamCountChan <- store.StoreResult{Data: teamCount, Err: err}
|
||||
close(teamCountChan)
|
||||
}()
|
||||
|
||||
@@ -150,7 +150,7 @@ func (a *App) trackActivity() {
|
||||
inactiveUserCount = iucr
|
||||
}
|
||||
|
||||
teamCount, err := a.Srv.Store.Team().AnalyticsTeamCount()
|
||||
teamCount, err := a.Srv.Store.Team().AnalyticsTeamCount(false)
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
|
||||
@@ -499,7 +499,7 @@ func (me *TestHelper) ResetEmojisMigration() {
|
||||
}
|
||||
|
||||
func (me *TestHelper) CheckTeamCount(t *testing.T, expected int64) {
|
||||
teamCount, err := me.App.Srv.Store.Team().AnalyticsTeamCount()
|
||||
teamCount, err := me.App.Srv.Store.Team().AnalyticsTeamCount(false)
|
||||
require.Nil(t, err, "Failed to get team count.")
|
||||
require.Equalf(t, teamCount, expected, "Unexpected number of teams. Expected: %v, found: %v", expected, teamCount)
|
||||
}
|
||||
|
||||
@@ -505,7 +505,7 @@ func TestImportImportTeam(t *testing.T) {
|
||||
scheme2 := th.SetupTeamScheme()
|
||||
|
||||
// Check how many teams are in the database.
|
||||
teamsCount, err := th.App.Srv.Store.Team().AnalyticsTeamCount()
|
||||
teamsCount, err := th.App.Srv.Store.Team().AnalyticsTeamCount(false)
|
||||
require.Nil(t, err, "Failed to get team count.")
|
||||
|
||||
data := TeamImportData{
|
||||
|
||||
@@ -76,7 +76,7 @@ func (s *Server) DoSecurityUpdateCheck() {
|
||||
v.Set(PROP_SECURITY_ACTIVE_USER_COUNT, strconv.FormatInt(ucr, 10))
|
||||
}
|
||||
|
||||
if teamCount, err := s.Store.Team().AnalyticsTeamCount(); err == nil {
|
||||
if teamCount, err := s.Store.Team().AnalyticsTeamCount(false); err == nil {
|
||||
v.Set(PROP_SECURITY_TEAM_COUNT, strconv.FormatInt(teamCount, 10))
|
||||
}
|
||||
|
||||
|
||||
@@ -659,7 +659,7 @@ func (a *App) GetAllTeamsPage(offset int, limit int) ([]*model.Team, *model.AppE
|
||||
}
|
||||
|
||||
func (a *App) GetAllTeamsPageWithCount(offset int, limit int) (*model.TeamsWithCount, *model.AppError) {
|
||||
totalCount, err := a.Srv.Store.Team().AnalyticsTeamCount()
|
||||
totalCount, err := a.Srv.Store.Team().AnalyticsTeamCount(true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -486,8 +486,18 @@ func (s SqlTeamStore) AnalyticsPrivateTeamCount() (int64, *model.AppError) {
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func (s SqlTeamStore) AnalyticsTeamCount() (int64, *model.AppError) {
|
||||
c, err := s.GetReplica().SelectInt("SELECT COUNT(*) FROM Teams WHERE DeleteAt = 0", map[string]interface{}{})
|
||||
func (s SqlTeamStore) AnalyticsTeamCount(includeDeleted bool) (int64, *model.AppError) {
|
||||
query := s.getQueryBuilder().Select("COUNT(*) FROM Teams")
|
||||
if !includeDeleted {
|
||||
query = query.Where(sq.Eq{"DeleteAt": 0})
|
||||
}
|
||||
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return 0, model.NewAppError("SqlTeamStore.AnalyticsTeamCount", "store.sql_team.analytics_team_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
c, err := s.GetReplica().SelectInt(queryString, args...)
|
||||
|
||||
if err != nil {
|
||||
return int64(0), model.NewAppError("SqlTeamStore.AnalyticsTeamCount", "store.sql_team.analytics_team_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
|
||||
@@ -80,7 +80,7 @@ type TeamStore interface {
|
||||
GetTeamsByUserId(userId string) ([]*model.Team, *model.AppError)
|
||||
GetByInviteId(inviteId string) (*model.Team, *model.AppError)
|
||||
PermanentDelete(teamId string) *model.AppError
|
||||
AnalyticsTeamCount() (int64, *model.AppError)
|
||||
AnalyticsTeamCount(includeDeleted bool) (int64, *model.AppError)
|
||||
AnalyticsPublicTeamCount() (int64, *model.AppError)
|
||||
AnalyticsPrivateTeamCount() (int64, *model.AppError)
|
||||
SaveMember(member *model.TeamMember, maxUsersPerTeam int) (*model.TeamMember, *model.AppError)
|
||||
|
||||
@@ -83,20 +83,20 @@ func (_m *TeamStore) AnalyticsPublicTeamCount() (int64, *model.AppError) {
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// AnalyticsTeamCount provides a mock function with given fields:
|
||||
func (_m *TeamStore) AnalyticsTeamCount() (int64, *model.AppError) {
|
||||
ret := _m.Called()
|
||||
// AnalyticsTeamCount provides a mock function with given fields: includeDeleted
|
||||
func (_m *TeamStore) AnalyticsTeamCount(includeDeleted bool) (int64, *model.AppError) {
|
||||
ret := _m.Called(includeDeleted)
|
||||
|
||||
var r0 int64
|
||||
if rf, ok := ret.Get(0).(func() int64); ok {
|
||||
r0 = rf()
|
||||
if rf, ok := ret.Get(0).(func(bool) int64); ok {
|
||||
r0 = rf(includeDeleted)
|
||||
} else {
|
||||
r0 = ret.Get(0).(int64)
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func() *model.AppError); ok {
|
||||
r1 = rf()
|
||||
if rf, ok := ret.Get(1).(func(bool) *model.AppError); ok {
|
||||
r1 = rf(includeDeleted)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
|
||||
@@ -778,12 +778,29 @@ func testTeamCount(t *testing.T, ss store.Store) {
|
||||
o1.Email = MakeEmail()
|
||||
o1.Type = model.TEAM_OPEN
|
||||
o1.AllowOpenInvite = true
|
||||
_, err := ss.Team().Save(&o1)
|
||||
team, err := ss.Team().Save(&o1)
|
||||
require.Nil(t, err)
|
||||
|
||||
teamCount, err := ss.Team().AnalyticsTeamCount()
|
||||
// not including deleted teams
|
||||
teamCount, err := ss.Team().AnalyticsTeamCount(false)
|
||||
require.Nil(t, err)
|
||||
require.NotEqual(t, 0, int(teamCount), "should be at least 1 team")
|
||||
|
||||
// delete the team for the next check
|
||||
team.DeleteAt = model.GetMillis()
|
||||
_, err = ss.Team().Update(team)
|
||||
require.Nil(t, err)
|
||||
|
||||
// get the count of teams not including deleted
|
||||
countNotIncludingDeleted, err := ss.Team().AnalyticsTeamCount(false)
|
||||
require.Nil(t, err)
|
||||
|
||||
// get the count of teams including deleted
|
||||
countIncludingDeleted, err := ss.Team().AnalyticsTeamCount(true)
|
||||
require.Nil(t, err)
|
||||
|
||||
// count including deleted should be one greater than not including deleted
|
||||
require.Equal(t, countNotIncludingDeleted+1, countIncludingDeleted)
|
||||
}
|
||||
|
||||
func testTeamMembers(t *testing.T, ss store.Store) {
|
||||
|
||||
@@ -5162,10 +5162,10 @@ func (s *TimerLayerTeamStore) AnalyticsPublicTeamCount() (int64, *model.AppError
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *TimerLayerTeamStore) AnalyticsTeamCount() (int64, *model.AppError) {
|
||||
func (s *TimerLayerTeamStore) AnalyticsTeamCount(includeDeleted bool) (int64, *model.AppError) {
|
||||
start := timemodule.Now()
|
||||
|
||||
resultVar0, resultVar1 := s.TeamStore.AnalyticsTeamCount()
|
||||
resultVar0, resultVar1 := s.TeamStore.AnalyticsTeamCount(includeDeleted)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
|
||||
Reference in New Issue
Block a user