diff --git a/app/diagnostics.go b/app/diagnostics.go index 33cef3eff5..90c8f7469b 100644 --- a/app/diagnostics.go +++ b/app/diagnostics.go @@ -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) diff --git a/store/sqlstore/user_store.go b/store/sqlstore/user_store.go index 1aa97226c3..170e96a394 100644 --- a/store/sqlstore/user_store.go +++ b/store/sqlstore/user_store.go @@ -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 { diff --git a/store/store.go b/store/store.go index db366804db..c3fc01dc12 100644 --- a/store/store.go +++ b/store/store.go @@ -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 diff --git a/store/storetest/mocks/UserStore.go b/store/storetest/mocks/UserStore.go index e859e71a2f..4f66a4de7a 100644 --- a/store/storetest/mocks/UserStore.go +++ b/store/storetest/mocks/UserStore.go @@ -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: diff --git a/store/storetest/user_store.go b/store/storetest/user_store.go index f9bf32b1c1..9171175230 100644 --- a/store/storetest/user_store.go +++ b/store/storetest/user_store.go @@ -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) } }