[MM-16173] Migrate Team.AnalyticsTeamCount to Sync by default #11126 (#11132)

* [MM-16173] Migrate Team.AnalyticsTeamCount to Sync by default #11126
+ Modified team_store.AnalyticsTeamCount to return (int64, *model.AppError) instead of store.StoreChannel.
+ Updated the mock store to reflect new return value.
+ Updated referencing code to handle new sync return value.

* Fix shadowing of the err

* Fix the empty line between related code

* Fix team count call to be an explicit async.

* Added error logging to diagnostics.go

* Fix gofmt in file
Этот коммит содержится в:
Kyle Reczek
2019-06-14 08:01:24 -06:00
коммит произвёл Christopher Poile
родитель e101e1c020
Коммит b61ded0ae4
9 изменённых файлов: 44 добавлений и 34 удалений

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

@@ -460,15 +460,14 @@ func (s SqlTeamStore) PermanentDelete(teamId string) store.StoreChannel {
})
}
func (s SqlTeamStore) AnalyticsTeamCount() store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
c, err := s.GetReplica().SelectInt("SELECT COUNT(*) FROM Teams WHERE DeleteAt = 0", map[string]interface{}{})
if err != nil {
result.Err = model.NewAppError("SqlTeamStore.AnalyticsTeamCount", "store.sql_team.analytics_team_count.app_error", nil, err.Error(), http.StatusInternalServerError)
return
}
result.Data = c
})
func (s SqlTeamStore) AnalyticsTeamCount() (int64, *model.AppError) {
c, err := s.GetReplica().SelectInt("SELECT COUNT(*) FROM Teams WHERE DeleteAt = 0", map[string]interface{}{})
if err != nil {
return int64(0), model.NewAppError("SqlTeamStore.AnalyticsTeamCount", "store.sql_team.analytics_team_count.app_error", nil, err.Error(), http.StatusInternalServerError)
}
return c, nil
}
func (s SqlTeamStore) getTeamMembersWithSchemeSelectQuery() sq.SelectBuilder {

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

@@ -99,7 +99,7 @@ type TeamStore interface {
GetTeamsByUserId(userId string) StoreChannel
GetByInviteId(inviteId string) (*model.Team, *model.AppError)
PermanentDelete(teamId string) StoreChannel
AnalyticsTeamCount() StoreChannel
AnalyticsTeamCount() (int64, *model.AppError)
SaveMember(member *model.TeamMember, maxUsersPerTeam int) StoreChannel
UpdateMember(member *model.TeamMember) StoreChannel
GetMember(teamId string, userId string) StoreChannel

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

@@ -30,19 +30,26 @@ func (_m *TeamStore) AnalyticsGetTeamCountForScheme(schemeId string) store.Store
}
// AnalyticsTeamCount provides a mock function with given fields:
func (_m *TeamStore) AnalyticsTeamCount() store.StoreChannel {
func (_m *TeamStore) AnalyticsTeamCount() (int64, *model.AppError) {
ret := _m.Called()
var r0 store.StoreChannel
if rf, ok := ret.Get(0).(func() store.StoreChannel); ok {
var r0 int64
if rf, ok := ret.Get(0).(func() int64); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel)
r0 = ret.Get(0).(int64)
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func() *model.AppError); ok {
r1 = rf()
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0
return r0, r1
}
// ClearAllCustomRoleAssignments provides a mock function with given fields:

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

@@ -768,10 +768,10 @@ func testTeamCount(t *testing.T, ss store.Store) {
_, err := ss.Team().Save(&o1)
require.Nil(t, err)
if r1 := <-ss.Team().AnalyticsTeamCount(); r1.Err != nil {
t.Fatal(r1.Err)
if teamCount, err := ss.Team().AnalyticsTeamCount(); err != nil {
t.Fatal(err)
} else {
if r1.Data.(int64) == 0 {
if teamCount == 0 {
t.Fatal("should be at least 1 team")
}
}