MM-20305: Adds ability to choose whether deleted teams are included in the count query. (#13181)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
a1a2bb3130
Коммит
31ac88ef69
@@ -84,7 +84,7 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||||||
|
|
||||||
teamCountChan := make(chan store.StoreResult, 1)
|
teamCountChan := make(chan store.StoreResult, 1)
|
||||||
go func() {
|
go func() {
|
||||||
teamCount, err := a.Srv.Store.Team().AnalyticsTeamCount()
|
teamCount, err := a.Srv.Store.Team().AnalyticsTeamCount(false)
|
||||||
teamCountChan <- store.StoreResult{Data: teamCount, Err: err}
|
teamCountChan <- store.StoreResult{Data: teamCount, Err: err}
|
||||||
close(teamCountChan)
|
close(teamCountChan)
|
||||||
}()
|
}()
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ func (a *App) trackActivity() {
|
|||||||
inactiveUserCount = iucr
|
inactiveUserCount = iucr
|
||||||
}
|
}
|
||||||
|
|
||||||
teamCount, err := a.Srv.Store.Team().AnalyticsTeamCount()
|
teamCount, err := a.Srv.Store.Team().AnalyticsTeamCount(false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mlog.Error(err.Error())
|
mlog.Error(err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -499,7 +499,7 @@ func (me *TestHelper) ResetEmojisMigration() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (me *TestHelper) CheckTeamCount(t *testing.T, expected int64) {
|
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.Nil(t, err, "Failed to get team count.")
|
||||||
require.Equalf(t, teamCount, expected, "Unexpected number of teams. Expected: %v, found: %v", expected, teamCount)
|
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()
|
scheme2 := th.SetupTeamScheme()
|
||||||
|
|
||||||
// Check how many teams are in the database.
|
// 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.")
|
require.Nil(t, err, "Failed to get team count.")
|
||||||
|
|
||||||
data := TeamImportData{
|
data := TeamImportData{
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ func (s *Server) DoSecurityUpdateCheck() {
|
|||||||
v.Set(PROP_SECURITY_ACTIVE_USER_COUNT, strconv.FormatInt(ucr, 10))
|
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))
|
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) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -486,8 +486,18 @@ func (s SqlTeamStore) AnalyticsPrivateTeamCount() (int64, *model.AppError) {
|
|||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlTeamStore) AnalyticsTeamCount() (int64, *model.AppError) {
|
func (s SqlTeamStore) AnalyticsTeamCount(includeDeleted bool) (int64, *model.AppError) {
|
||||||
c, err := s.GetReplica().SelectInt("SELECT COUNT(*) FROM Teams WHERE DeleteAt = 0", map[string]interface{}{})
|
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 {
|
if err != nil {
|
||||||
return int64(0), model.NewAppError("SqlTeamStore.AnalyticsTeamCount", "store.sql_team.analytics_team_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
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)
|
GetTeamsByUserId(userId string) ([]*model.Team, *model.AppError)
|
||||||
GetByInviteId(inviteId string) (*model.Team, *model.AppError)
|
GetByInviteId(inviteId string) (*model.Team, *model.AppError)
|
||||||
PermanentDelete(teamId string) *model.AppError
|
PermanentDelete(teamId string) *model.AppError
|
||||||
AnalyticsTeamCount() (int64, *model.AppError)
|
AnalyticsTeamCount(includeDeleted bool) (int64, *model.AppError)
|
||||||
AnalyticsPublicTeamCount() (int64, *model.AppError)
|
AnalyticsPublicTeamCount() (int64, *model.AppError)
|
||||||
AnalyticsPrivateTeamCount() (int64, *model.AppError)
|
AnalyticsPrivateTeamCount() (int64, *model.AppError)
|
||||||
SaveMember(member *model.TeamMember, maxUsersPerTeam int) (*model.TeamMember, *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
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// AnalyticsTeamCount provides a mock function with given fields:
|
// AnalyticsTeamCount provides a mock function with given fields: includeDeleted
|
||||||
func (_m *TeamStore) AnalyticsTeamCount() (int64, *model.AppError) {
|
func (_m *TeamStore) AnalyticsTeamCount(includeDeleted bool) (int64, *model.AppError) {
|
||||||
ret := _m.Called()
|
ret := _m.Called(includeDeleted)
|
||||||
|
|
||||||
var r0 int64
|
var r0 int64
|
||||||
if rf, ok := ret.Get(0).(func() int64); ok {
|
if rf, ok := ret.Get(0).(func(bool) int64); ok {
|
||||||
r0 = rf()
|
r0 = rf(includeDeleted)
|
||||||
} else {
|
} else {
|
||||||
r0 = ret.Get(0).(int64)
|
r0 = ret.Get(0).(int64)
|
||||||
}
|
}
|
||||||
|
|
||||||
var r1 *model.AppError
|
var r1 *model.AppError
|
||||||
if rf, ok := ret.Get(1).(func() *model.AppError); ok {
|
if rf, ok := ret.Get(1).(func(bool) *model.AppError); ok {
|
||||||
r1 = rf()
|
r1 = rf(includeDeleted)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(1) != nil {
|
if ret.Get(1) != nil {
|
||||||
r1 = ret.Get(1).(*model.AppError)
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
|||||||
@@ -778,12 +778,29 @@ func testTeamCount(t *testing.T, ss store.Store) {
|
|||||||
o1.Email = MakeEmail()
|
o1.Email = MakeEmail()
|
||||||
o1.Type = model.TEAM_OPEN
|
o1.Type = model.TEAM_OPEN
|
||||||
o1.AllowOpenInvite = true
|
o1.AllowOpenInvite = true
|
||||||
_, err := ss.Team().Save(&o1)
|
team, err := ss.Team().Save(&o1)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
teamCount, err := ss.Team().AnalyticsTeamCount()
|
// not including deleted teams
|
||||||
|
teamCount, err := ss.Team().AnalyticsTeamCount(false)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.NotEqual(t, 0, int(teamCount), "should be at least 1 team")
|
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) {
|
func testTeamMembers(t *testing.T, ss store.Store) {
|
||||||
|
|||||||
@@ -5162,10 +5162,10 @@ func (s *TimerLayerTeamStore) AnalyticsPublicTeamCount() (int64, *model.AppError
|
|||||||
return resultVar0, resultVar1
|
return resultVar0, resultVar1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TimerLayerTeamStore) AnalyticsTeamCount() (int64, *model.AppError) {
|
func (s *TimerLayerTeamStore) AnalyticsTeamCount(includeDeleted bool) (int64, *model.AppError) {
|
||||||
start := timemodule.Now()
|
start := timemodule.Now()
|
||||||
|
|
||||||
resultVar0, resultVar1 := s.TeamStore.AnalyticsTeamCount()
|
resultVar0, resultVar1 := s.TeamStore.AnalyticsTeamCount(includeDeleted)
|
||||||
|
|
||||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||||
if s.Root.Metrics != nil {
|
if s.Root.Metrics != nil {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user