MM-20305: Adds ability to choose whether deleted teams are included in the count query. (#13181)

Этот коммит содержится в:
Martin Kraft
2019-11-27 07:50:15 -05:00
коммит произвёл GitHub
родитель a1a2bb3130
Коммит 31ac88ef69
11 изменённых файлов: 47 добавлений и 20 удалений

Просмотреть файл

@@ -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 {