[MM-16572] Migrate "User.AnalyticsGetSystemAdminCount" to Sync by default (#11484)

Этот коммит содержится в:
SezalAgrawal
2019-07-02 14:51:38 +05:30
коммит произвёл Hanzei
родитель b664291f21
Коммит f881b00650
5 изменённых файлов: 28 добавлений и 23 удалений

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

@@ -708,8 +708,8 @@ func (a *App) trackServer() {
"operating_system": runtime.GOOS,
}
if scr := <-a.Srv.Store.User().AnalyticsGetSystemAdminCount(); scr.Err == nil {
data["system_admins"] = scr.Data.(int64)
if scr, err := a.Srv.Store.User().AnalyticsGetSystemAdminCount(); err == nil {
data["system_admins"] = scr
}
a.SendDiagnostic(TRACK_SERVER, data)

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

@@ -1427,14 +1427,12 @@ func (us SqlUserStore) AnalyticsGetInactiveUsersCount() (int64, *model.AppError)
return count, nil
}
func (us SqlUserStore) AnalyticsGetSystemAdminCount() store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
if count, err := us.GetReplica().SelectInt("SELECT count(*) FROM Users WHERE Roles LIKE :Roles and DeleteAt = 0", map[string]interface{}{"Roles": "%system_admin%"}); err != nil {
result.Err = model.NewAppError("SqlUserStore.AnalyticsGetSystemAdminCount", "store.sql_user.analytics_get_system_admin_count.app_error", nil, err.Error(), http.StatusInternalServerError)
} else {
result.Data = count
}
})
func (us SqlUserStore) AnalyticsGetSystemAdminCount() (int64, *model.AppError) {
count, err := us.GetReplica().SelectInt("SELECT count(*) FROM Users WHERE Roles LIKE :Roles and DeleteAt = 0", map[string]interface{}{"Roles": "%system_admin%"})
if err != nil {
return int64(0), model.NewAppError("SqlUserStore.AnalyticsGetSystemAdminCount", "store.sql_user.analytics_get_system_admin_count.app_error", nil, err.Error(), http.StatusInternalServerError)
}
return count, nil
}
func (us SqlUserStore) GetProfilesNotInTeam(teamId string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) store.StoreChannel {

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

@@ -294,7 +294,7 @@ type UserStore interface {
SearchNotInChannel(teamId string, channelId string, term string, options *model.UserSearchOptions) StoreChannel
SearchWithoutTeam(term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
AnalyticsGetInactiveUsersCount() (int64, *model.AppError)
AnalyticsGetSystemAdminCount() StoreChannel
AnalyticsGetSystemAdminCount() (int64, *model.AppError)
GetProfilesNotInTeam(teamId string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) StoreChannel
GetEtagForProfilesNotInTeam(teamId string) StoreChannel
ClearAllCustomRoleAssignments() StoreChannel

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

@@ -53,19 +53,26 @@ func (_m *UserStore) AnalyticsGetInactiveUsersCount() (int64, *model.AppError) {
}
// AnalyticsGetSystemAdminCount provides a mock function with given fields:
func (_m *UserStore) AnalyticsGetSystemAdminCount() store.StoreChannel {
func (_m *UserStore) AnalyticsGetSystemAdminCount() (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:

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

@@ -3252,10 +3252,10 @@ func testUserStoreAnalyticsGetInactiveUsersCount(t *testing.T, ss store.Store) {
func testUserStoreAnalyticsGetSystemAdminCount(t *testing.T, ss store.Store) {
var countBefore int64
if result := <-ss.User().AnalyticsGetSystemAdminCount(); result.Err != nil {
t.Fatal(result.Err)
if result, err := ss.User().AnalyticsGetSystemAdminCount(); err != nil {
t.Fatal(err)
} else {
countBefore = result.Data.(int64)
countBefore = result
}
u1 := model.User{}
@@ -3277,11 +3277,11 @@ func testUserStoreAnalyticsGetSystemAdminCount(t *testing.T, ss store.Store) {
}
defer func() { require.Nil(t, ss.User().PermanentDelete(u2.Id)) }()
if result := <-ss.User().AnalyticsGetSystemAdminCount(); result.Err != nil {
t.Fatal(result.Err)
if result, err := ss.User().AnalyticsGetSystemAdminCount(); err != nil {
t.Fatal(err)
} else {
// We expect to find 1 more system admin than there was at the start of this test function.
if count := result.Data.(int64); count != countBefore+1 {
if count := result; count != countBefore+1 {
t.Fatal("Did not get the expected number of system admins. Expected, got: ", countBefore+1, count)
}
}