GH-11385 Migrate User.AnalyticsGetInactiveUsersCount to Sync by default (#11432)
* GH-11385 Migrate User.AnalyticsGetInactiveUsersCount to Sync by default * GH-11385 fix TestGetAnalyticsOld
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
46f2b18e4f
Коммит
3bce32bbcf
@@ -59,7 +59,12 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||||||
var userChan store.StoreChannel
|
var userChan store.StoreChannel
|
||||||
var userInactiveChan store.StoreChannel
|
var userInactiveChan store.StoreChannel
|
||||||
if teamId == "" {
|
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 {
|
} else {
|
||||||
userChan := make(chan store.StoreResult, 1)
|
userChan := make(chan store.StoreResult, 1)
|
||||||
go func() {
|
go func() {
|
||||||
|
|||||||
@@ -157,8 +157,8 @@ func (a *App) trackActivity() {
|
|||||||
botAccountsCount = count
|
botAccountsCount = count
|
||||||
}
|
}
|
||||||
|
|
||||||
if iucr := <-a.Srv.Store.User().AnalyticsGetInactiveUsersCount(); iucr.Err == nil {
|
if iucr, err := a.Srv.Store.User().AnalyticsGetInactiveUsersCount(); err == nil {
|
||||||
inactiveUserCount = iucr.Data.(int64)
|
inactiveUserCount = iucr
|
||||||
}
|
}
|
||||||
|
|
||||||
teamCount, err := a.Srv.Store.Team().AnalyticsTeamCount()
|
teamCount, err := a.Srv.Store.Team().AnalyticsTeamCount()
|
||||||
|
|||||||
@@ -1417,14 +1417,12 @@ func (us SqlUserStore) performSearch(query sq.SelectBuilder, term string, option
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us SqlUserStore) AnalyticsGetInactiveUsersCount() store.StoreChannel {
|
func (us SqlUserStore) AnalyticsGetInactiveUsersCount() (int64, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
count, err := us.GetReplica().SelectInt("SELECT COUNT(Id) FROM Users WHERE DeleteAt > 0")
|
||||||
if count, err := us.GetReplica().SelectInt("SELECT COUNT(Id) FROM Users WHERE DeleteAt > 0"); err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlUserStore.AnalyticsGetInactiveUsersCount", "store.sql_user.analytics_get_inactive_users_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return int64(0), model.NewAppError("SqlUserStore.AnalyticsGetInactiveUsersCount", "store.sql_user.analytics_get_inactive_users_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
} else {
|
}
|
||||||
result.Data = count
|
return count, nil
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us SqlUserStore) AnalyticsGetSystemAdminCount() store.StoreChannel {
|
func (us SqlUserStore) AnalyticsGetSystemAdminCount() store.StoreChannel {
|
||||||
|
|||||||
@@ -293,7 +293,7 @@ type UserStore interface {
|
|||||||
SearchInChannel(channelId string, term string, options *model.UserSearchOptions) StoreChannel
|
SearchInChannel(channelId string, term string, options *model.UserSearchOptions) StoreChannel
|
||||||
SearchNotInChannel(teamId string, 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)
|
SearchWithoutTeam(term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
||||||
AnalyticsGetInactiveUsersCount() StoreChannel
|
AnalyticsGetInactiveUsersCount() (int64, *model.AppError)
|
||||||
AnalyticsGetSystemAdminCount() StoreChannel
|
AnalyticsGetSystemAdminCount() StoreChannel
|
||||||
GetProfilesNotInTeam(teamId string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) StoreChannel
|
GetProfilesNotInTeam(teamId string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) StoreChannel
|
||||||
GetEtagForProfilesNotInTeam(teamId string) StoreChannel
|
GetEtagForProfilesNotInTeam(teamId string) StoreChannel
|
||||||
|
|||||||
@@ -30,19 +30,26 @@ func (_m *UserStore) AnalyticsActiveCount(time int64) store.StoreChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AnalyticsGetInactiveUsersCount provides a mock function with given fields:
|
// AnalyticsGetInactiveUsersCount provides a mock function with given fields:
|
||||||
func (_m *UserStore) AnalyticsGetInactiveUsersCount() store.StoreChannel {
|
func (_m *UserStore) AnalyticsGetInactiveUsersCount() (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
|
||||||
}
|
}
|
||||||
|
|
||||||
// AnalyticsGetSystemAdminCount provides a mock function with given fields:
|
// AnalyticsGetSystemAdminCount provides a mock function with given fields:
|
||||||
|
|||||||
@@ -3229,12 +3229,9 @@ func testUserStoreAnalyticsGetInactiveUsersCount(t *testing.T, ss store.Store) {
|
|||||||
store.Must(ss.User().Save(u1))
|
store.Must(ss.User().Save(u1))
|
||||||
defer func() { require.Nil(t, ss.User().PermanentDelete(u1.Id)) }()
|
defer func() { require.Nil(t, ss.User().PermanentDelete(u1.Id)) }()
|
||||||
|
|
||||||
var count int64
|
count, err := ss.User().AnalyticsGetInactiveUsersCount()
|
||||||
|
if err != nil {
|
||||||
if result := <-ss.User().AnalyticsGetInactiveUsersCount(); result.Err != nil {
|
t.Fatal(err)
|
||||||
t.Fatal(result.Err)
|
|
||||||
} else {
|
|
||||||
count = result.Data.(int64)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u2 := &model.User{}
|
u2 := &model.User{}
|
||||||
@@ -3243,13 +3240,13 @@ func testUserStoreAnalyticsGetInactiveUsersCount(t *testing.T, ss store.Store) {
|
|||||||
store.Must(ss.User().Save(u2))
|
store.Must(ss.User().Save(u2))
|
||||||
defer func() { require.Nil(t, ss.User().PermanentDelete(u2.Id)) }()
|
defer func() { require.Nil(t, ss.User().PermanentDelete(u2.Id)) }()
|
||||||
|
|
||||||
if result := <-ss.User().AnalyticsGetInactiveUsersCount(); result.Err != nil {
|
newCount, err := ss.User().AnalyticsGetInactiveUsersCount()
|
||||||
t.Fatal(result.Err)
|
if err != nil {
|
||||||
} else {
|
t.Fatal(err)
|
||||||
newCount := result.Data.(int64)
|
}
|
||||||
if count != newCount-1 {
|
|
||||||
t.Fatal("Expected 1 more inactive users but found otherwise.", count, newCount)
|
if count != newCount-1 {
|
||||||
}
|
t.Fatal("Expected 1 more inactive users but found otherwise.", count, newCount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user