GH-11385 Migrate User.AnalyticsGetInactiveUsersCount to Sync by default (#11432)

* GH-11385 Migrate User.AnalyticsGetInactiveUsersCount to Sync by default

* GH-11385 fix TestGetAnalyticsOld
This commit is contained in:
Marc Argent
2019-06-28 15:39:53 +01:00
committed by Christopher Speller
parent 46f2b18e4f
commit 3bce32bbcf
6 changed files with 38 additions and 31 deletions

View File

@@ -59,7 +59,12 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
var userChan store.StoreChannel
var userInactiveChan store.StoreChannel
if teamId == "" {
userInactiveChan = a.Srv.Store.User().AnalyticsGetInactiveUsersCount()
userInactiveChan = make(chan store.StoreResult, 1)
go func() {
count, err := a.Srv.Store.User().AnalyticsGetInactiveUsersCount()
userInactiveChan <- store.StoreResult{Data: count, Err: err}
close(userInactiveChan)
}()
} else {
userChan := make(chan store.StoreResult, 1)
go func() {

View File

@@ -157,8 +157,8 @@ func (a *App) trackActivity() {
botAccountsCount = count
}
if iucr := <-a.Srv.Store.User().AnalyticsGetInactiveUsersCount(); iucr.Err == nil {
inactiveUserCount = iucr.Data.(int64)
if iucr, err := a.Srv.Store.User().AnalyticsGetInactiveUsersCount(); err == nil {
inactiveUserCount = iucr
}
teamCount, err := a.Srv.Store.Team().AnalyticsTeamCount()

View File

@@ -1417,14 +1417,12 @@ func (us SqlUserStore) performSearch(query sq.SelectBuilder, term string, option
return result
}
func (us SqlUserStore) AnalyticsGetInactiveUsersCount() store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
if count, err := us.GetReplica().SelectInt("SELECT COUNT(Id) FROM Users WHERE DeleteAt > 0"); err != nil {
result.Err = model.NewAppError("SqlUserStore.AnalyticsGetInactiveUsersCount", "store.sql_user.analytics_get_inactive_users_count.app_error", nil, err.Error(), http.StatusInternalServerError)
} else {
result.Data = count
}
})
func (us SqlUserStore) AnalyticsGetInactiveUsersCount() (int64, *model.AppError) {
count, err := us.GetReplica().SelectInt("SELECT COUNT(Id) FROM Users WHERE DeleteAt > 0")
if err != nil {
return int64(0), model.NewAppError("SqlUserStore.AnalyticsGetInactiveUsersCount", "store.sql_user.analytics_get_inactive_users_count.app_error", nil, err.Error(), http.StatusInternalServerError)
}
return count, nil
}
func (us SqlUserStore) AnalyticsGetSystemAdminCount() store.StoreChannel {

View File

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

View File

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

View File

@@ -3229,12 +3229,9 @@ func testUserStoreAnalyticsGetInactiveUsersCount(t *testing.T, ss store.Store) {
store.Must(ss.User().Save(u1))
defer func() { require.Nil(t, ss.User().PermanentDelete(u1.Id)) }()
var count int64
if result := <-ss.User().AnalyticsGetInactiveUsersCount(); result.Err != nil {
t.Fatal(result.Err)
} else {
count = result.Data.(int64)
count, err := ss.User().AnalyticsGetInactiveUsersCount()
if err != nil {
t.Fatal(err)
}
u2 := &model.User{}
@@ -3243,13 +3240,13 @@ func testUserStoreAnalyticsGetInactiveUsersCount(t *testing.T, ss store.Store) {
store.Must(ss.User().Save(u2))
defer func() { require.Nil(t, ss.User().PermanentDelete(u2.Id)) }()
if result := <-ss.User().AnalyticsGetInactiveUsersCount(); result.Err != nil {
t.Fatal(result.Err)
} else {
newCount := result.Data.(int64)
if count != newCount-1 {
t.Fatal("Expected 1 more inactive users but found otherwise.", count, newCount)
}
newCount, err := ss.User().AnalyticsGetInactiveUsersCount()
if err != nil {
t.Fatal(err)
}
if count != newCount-1 {
t.Fatal("Expected 1 more inactive users but found otherwise.", count, newCount)
}
}