* [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
Этот коммит содержится в:
коммит произвёл
Christopher Poile
родитель
e101e1c020
Коммит
b61ded0ae4
@@ -46,7 +46,6 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||||||
|
|
||||||
openChan := a.Srv.Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_OPEN)
|
openChan := a.Srv.Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_OPEN)
|
||||||
privateChan := a.Srv.Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_PRIVATE)
|
privateChan := a.Srv.Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_PRIVATE)
|
||||||
teamChan := a.Srv.Store.Team().AnalyticsTeamCount()
|
|
||||||
|
|
||||||
var userChan store.StoreChannel
|
var userChan store.StoreChannel
|
||||||
var userInactiveChan store.StoreChannel
|
var userInactiveChan store.StoreChannel
|
||||||
@@ -65,6 +64,12 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||||||
|
|
||||||
dailyActiveChan := a.Srv.Store.User().AnalyticsActiveCount(DAY_MILLISECONDS)
|
dailyActiveChan := a.Srv.Store.User().AnalyticsActiveCount(DAY_MILLISECONDS)
|
||||||
monthlyActiveChan := a.Srv.Store.User().AnalyticsActiveCount(MONTH_MILLISECONDS)
|
monthlyActiveChan := a.Srv.Store.User().AnalyticsActiveCount(MONTH_MILLISECONDS)
|
||||||
|
teamCountChan := make(chan store.StoreResult, 1)
|
||||||
|
go func() {
|
||||||
|
teamCount, err := a.Srv.Store.Team().AnalyticsTeamCount()
|
||||||
|
teamCountChan <- store.StoreResult{Data: teamCount, Err: err}
|
||||||
|
close(teamCountChan)
|
||||||
|
}()
|
||||||
|
|
||||||
r := <-openChan
|
r := <-openChan
|
||||||
if r.Err != nil {
|
if r.Err != nil {
|
||||||
@@ -108,7 +113,7 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||||||
rows[10].Value = float64(r.Data.(int64))
|
rows[10].Value = float64(r.Data.(int64))
|
||||||
}
|
}
|
||||||
|
|
||||||
r = <-teamChan
|
r = <-teamCountChan
|
||||||
if r.Err != nil {
|
if r.Err != nil {
|
||||||
return nil, r.Err
|
return nil, r.Err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -166,8 +166,9 @@ func (a *App) trackActivity() {
|
|||||||
inactiveUserCount = iucr.Data.(int64)
|
inactiveUserCount = iucr.Data.(int64)
|
||||||
}
|
}
|
||||||
|
|
||||||
if tcr := <-a.Srv.Store.Team().AnalyticsTeamCount(); tcr.Err == nil {
|
teamCount, err := a.Srv.Store.Team().AnalyticsTeamCount()
|
||||||
teamCount = tcr.Data.(int64)
|
if err != nil {
|
||||||
|
mlog.Error(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if ucc := <-a.Srv.Store.Channel().AnalyticsTypeCount("", "O"); ucc.Err == nil {
|
if ucc := <-a.Srv.Store.Channel().AnalyticsTypeCount("", "O"); ucc.Err == nil {
|
||||||
|
|||||||
@@ -478,13 +478,13 @@ func (me *TestHelper) ResetEmojisMigration() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (me *TestHelper) CheckTeamCount(t *testing.T, expected int64) {
|
func (me *TestHelper) CheckTeamCount(t *testing.T, expected int64) {
|
||||||
if r := <-me.App.Srv.Store.Team().AnalyticsTeamCount(); r.Err == nil {
|
teamCount, err := me.App.Srv.Store.Team().AnalyticsTeamCount()
|
||||||
if r.Data.(int64) != expected {
|
if err != nil {
|
||||||
t.Fatalf("Unexpected number of teams. Expected: %v, found: %v", expected, r.Data.(int64))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
t.Fatalf("Failed to get team count.")
|
t.Fatalf("Failed to get team count.")
|
||||||
}
|
}
|
||||||
|
if teamCount != expected {
|
||||||
|
t.Fatalf("Unexpected number of teams. Expected: %v, found: %v", expected, teamCount)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (me *TestHelper) CheckChannelsCount(t *testing.T, expected int64) {
|
func (me *TestHelper) CheckChannelsCount(t *testing.T, expected int64) {
|
||||||
|
|||||||
@@ -568,10 +568,8 @@ 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.
|
||||||
var teamsCount int64
|
teamsCount, err := th.App.Srv.Store.Team().AnalyticsTeamCount()
|
||||||
if r := <-th.App.Srv.Store.Team().AnalyticsTeamCount(); r.Err == nil {
|
if err != nil {
|
||||||
teamsCount = r.Data.(int64)
|
|
||||||
} else {
|
|
||||||
t.Fatalf("Failed to get team count.")
|
t.Fatalf("Failed to get team count.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -79,8 +79,8 @@ func (s *Server) DoSecurityUpdateCheck() {
|
|||||||
v.Set(PROP_SECURITY_ACTIVE_USER_COUNT, strconv.FormatInt(ucr.Data.(int64), 10))
|
v.Set(PROP_SECURITY_ACTIVE_USER_COUNT, strconv.FormatInt(ucr.Data.(int64), 10))
|
||||||
}
|
}
|
||||||
|
|
||||||
if tcr := <-s.Store.Team().AnalyticsTeamCount(); tcr.Err == nil {
|
if teamCount, err := s.Store.Team().AnalyticsTeamCount(); err == nil {
|
||||||
v.Set(PROP_SECURITY_TEAM_COUNT, strconv.FormatInt(tcr.Data.(int64), 10))
|
v.Set(PROP_SECURITY_TEAM_COUNT, strconv.FormatInt(teamCount, 10))
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := http.Get(SECURITY_URL + "/security?" + v.Encode())
|
res, err := http.Get(SECURITY_URL + "/security?" + v.Encode())
|
||||||
|
|||||||
@@ -460,15 +460,14 @@ func (s SqlTeamStore) PermanentDelete(teamId string) store.StoreChannel {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlTeamStore) AnalyticsTeamCount() store.StoreChannel {
|
func (s SqlTeamStore) AnalyticsTeamCount() (int64, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
c, err := s.GetReplica().SelectInt("SELECT COUNT(*) FROM Teams WHERE DeleteAt = 0", map[string]interface{}{})
|
||||||
c, err := s.GetReplica().SelectInt("SELECT COUNT(*) FROM Teams WHERE DeleteAt = 0", map[string]interface{}{})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = 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)
|
||||||
return
|
}
|
||||||
}
|
|
||||||
result.Data = c
|
return c, nil
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlTeamStore) getTeamMembersWithSchemeSelectQuery() sq.SelectBuilder {
|
func (s SqlTeamStore) getTeamMembersWithSchemeSelectQuery() sq.SelectBuilder {
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ type TeamStore interface {
|
|||||||
GetTeamsByUserId(userId string) StoreChannel
|
GetTeamsByUserId(userId string) StoreChannel
|
||||||
GetByInviteId(inviteId string) (*model.Team, *model.AppError)
|
GetByInviteId(inviteId string) (*model.Team, *model.AppError)
|
||||||
PermanentDelete(teamId string) StoreChannel
|
PermanentDelete(teamId string) StoreChannel
|
||||||
AnalyticsTeamCount() StoreChannel
|
AnalyticsTeamCount() (int64, *model.AppError)
|
||||||
SaveMember(member *model.TeamMember, maxUsersPerTeam int) StoreChannel
|
SaveMember(member *model.TeamMember, maxUsersPerTeam int) StoreChannel
|
||||||
UpdateMember(member *model.TeamMember) StoreChannel
|
UpdateMember(member *model.TeamMember) StoreChannel
|
||||||
GetMember(teamId string, userId string) 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:
|
// AnalyticsTeamCount provides a mock function with given fields:
|
||||||
func (_m *TeamStore) AnalyticsTeamCount() store.StoreChannel {
|
func (_m *TeamStore) AnalyticsTeamCount() (int64, *model.AppError) {
|
||||||
ret := _m.Called()
|
ret := _m.Called()
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 int64
|
||||||
if rf, ok := ret.Get(0).(func() store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func() int64); ok {
|
||||||
r0 = rf()
|
r0 = rf()
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
r0 = ret.Get(0).(int64)
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
}
|
||||||
|
|
||||||
|
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:
|
// 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)
|
_, err := ss.Team().Save(&o1)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
if r1 := <-ss.Team().AnalyticsTeamCount(); r1.Err != nil {
|
if teamCount, err := ss.Team().AnalyticsTeamCount(); err != nil {
|
||||||
t.Fatal(r1.Err)
|
t.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
if r1.Data.(int64) == 0 {
|
if teamCount == 0 {
|
||||||
t.Fatal("should be at least 1 team")
|
t.Fatal("should be at least 1 team")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user