MM-16780 Migrate "Team.AnalyticsGetTeamCountForScheme" to Sync by default (#11588)

* Changed the implementation of AnalyticsGetTeamCountForScheme to sync

* Updated the Store interface

* Updated the AnalyticsGetTeamCountForScheme tests

* Updated the autogenerated mocks

* Updated trackPermissions to use the modified method
This commit is contained in:
Tim Scheuermann
2019-07-17 01:10:30 +02:00
committed by Jesús Espino
parent 1cb32b2331
commit 1da858ac4c
5 changed files with 32 additions and 25 deletions

View File

@@ -826,10 +826,7 @@ func (a *App) trackPermissions() {
channelGuestPermissions = strings.Join(role.Permissions, " ")
}
var count int64 = 0
if res := <-a.Srv.Store.Team().AnalyticsGetTeamCountForScheme(scheme.Id); res.Err == nil {
count = res.Data.(int64)
}
count, _ := a.Srv.Store.Team().AnalyticsGetTeamCountForScheme(scheme.Id)
a.SendDiagnostic(TRACK_PERMISSIONS_TEAM_SCHEMES, map[string]interface{}{
"scheme_id": scheme.Id,

View File

@@ -940,15 +940,13 @@ func (s SqlTeamStore) ClearAllCustomRoleAssignments() *model.AppError {
return nil
}
func (s SqlTeamStore) AnalyticsGetTeamCountForScheme(schemeId string) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
count, err := s.GetReplica().SelectInt("SELECT count(*) FROM Teams WHERE SchemeId = :SchemeId AND DeleteAt = 0", map[string]interface{}{"SchemeId": schemeId})
if err != nil {
result.Err = model.NewAppError("SqlTeamStore.AnalyticsGetTeamCountForScheme", "store.sql_team.analytics_get_team_count_for_scheme.app_error", nil, "schemeId="+schemeId+" "+err.Error(), http.StatusInternalServerError)
return
}
result.Data = count
})
func (s SqlTeamStore) AnalyticsGetTeamCountForScheme(schemeId string) (int64, *model.AppError) {
count, err := s.GetReplica().SelectInt("SELECT count(*) FROM Teams WHERE SchemeId = :SchemeId AND DeleteAt = 0", map[string]interface{}{"SchemeId": schemeId})
if err != nil {
return 0, model.NewAppError("SqlTeamStore.AnalyticsGetTeamCountForScheme", "store.sql_team.analytics_get_team_count_for_scheme.app_error", nil, "schemeId="+schemeId+" "+err.Error(), http.StatusInternalServerError)
}
return count, nil
}
func (s SqlTeamStore) GetAllForExportAfter(limit int, afterId string) ([]*model.TeamForExport, *model.AppError) {

View File

@@ -119,7 +119,7 @@ type TeamStore interface {
MigrateTeamMembers(fromTeamId string, fromUserId string) (map[string]string, *model.AppError)
ResetAllTeamSchemes() *model.AppError
ClearAllCustomRoleAssignments() *model.AppError
AnalyticsGetTeamCountForScheme(schemeId string) StoreChannel
AnalyticsGetTeamCountForScheme(schemeId string) (int64, *model.AppError)
GetAllForExportAfter(limit int, afterId string) ([]*model.TeamForExport, *model.AppError)
GetTeamMembersForExport(userId string) ([]*model.TeamMemberForExport, *model.AppError)
UserBelongsToTeams(userId string, teamIds []string) (bool, *model.AppError)

View File

@@ -14,19 +14,26 @@ type TeamStore struct {
}
// AnalyticsGetTeamCountForScheme provides a mock function with given fields: schemeId
func (_m *TeamStore) AnalyticsGetTeamCountForScheme(schemeId string) store.StoreChannel {
func (_m *TeamStore) AnalyticsGetTeamCountForScheme(schemeId string) (int64, *model.AppError) {
ret := _m.Called(schemeId)
var r0 store.StoreChannel
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
var r0 int64
if rf, ok := ret.Get(0).(func(string) int64); ok {
r0 = rf(schemeId)
} 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(string) *model.AppError); ok {
r1 = rf(schemeId)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0
return r0, r1
}
// AnalyticsTeamCount provides a mock function with given fields:

View File

@@ -1545,7 +1545,8 @@ func testTeamStoreAnalyticsGetTeamCountForScheme(t *testing.T, ss store.Store) {
s1, err := ss.Scheme().Save(s1)
require.Nil(t, err)
count1 := (<-ss.Team().AnalyticsGetTeamCountForScheme(s1.Id)).Data.(int64)
count1, err := ss.Team().AnalyticsGetTeamCountForScheme(s1.Id)
assert.Nil(t, err)
assert.Equal(t, int64(0), count1)
t1 := &model.Team{
@@ -1558,7 +1559,8 @@ func testTeamStoreAnalyticsGetTeamCountForScheme(t *testing.T, ss store.Store) {
_, err = ss.Team().Save(t1)
require.Nil(t, err)
count2 := (<-ss.Team().AnalyticsGetTeamCountForScheme(s1.Id)).Data.(int64)
count2, err := ss.Team().AnalyticsGetTeamCountForScheme(s1.Id)
assert.Nil(t, err)
assert.Equal(t, int64(1), count2)
t2 := &model.Team{
@@ -1571,7 +1573,8 @@ func testTeamStoreAnalyticsGetTeamCountForScheme(t *testing.T, ss store.Store) {
_, err = ss.Team().Save(t2)
require.Nil(t, err)
count3 := (<-ss.Team().AnalyticsGetTeamCountForScheme(s1.Id)).Data.(int64)
count3, err := ss.Team().AnalyticsGetTeamCountForScheme(s1.Id)
assert.Nil(t, err)
assert.Equal(t, int64(2), count3)
t3 := &model.Team{
@@ -1583,7 +1586,8 @@ func testTeamStoreAnalyticsGetTeamCountForScheme(t *testing.T, ss store.Store) {
_, err = ss.Team().Save(t3)
require.Nil(t, err)
count4 := (<-ss.Team().AnalyticsGetTeamCountForScheme(s1.Id)).Data.(int64)
count4, err := ss.Team().AnalyticsGetTeamCountForScheme(s1.Id)
assert.Nil(t, err)
assert.Equal(t, int64(2), count4)
t4 := &model.Team{
@@ -1597,7 +1601,8 @@ func testTeamStoreAnalyticsGetTeamCountForScheme(t *testing.T, ss store.Store) {
_, err = ss.Team().Save(t4)
require.Nil(t, err)
count5 := (<-ss.Team().AnalyticsGetTeamCountForScheme(s1.Id)).Data.(int64)
count5, err := ss.Team().AnalyticsGetTeamCountForScheme(s1.Id)
assert.Nil(t, err)
assert.Equal(t, int64(2), count5)
}