MM-16521 Migrate "Status.GetTotalActiveUsersCount" to Sync by default (#11401)
* initial code * remove repeated var declaration
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
130873c2f1
Коммит
30d572000a
@@ -75,8 +75,8 @@ func (s *Server) DoSecurityUpdateCheck() {
|
|||||||
v.Set(PROP_SECURITY_USER_COUNT, strconv.FormatInt(ucr.Data.(int64), 10))
|
v.Set(PROP_SECURITY_USER_COUNT, strconv.FormatInt(ucr.Data.(int64), 10))
|
||||||
}
|
}
|
||||||
|
|
||||||
if ucr := <-s.Store.Status().GetTotalActiveUsersCount(); ucr.Err == nil {
|
if ucr, err := s.Store.Status().GetTotalActiveUsersCount(); err == nil {
|
||||||
v.Set(PROP_SECURITY_ACTIVE_USER_COUNT, strconv.FormatInt(ucr.Data.(int64), 10))
|
v.Set(PROP_SECURITY_ACTIVE_USER_COUNT, strconv.FormatInt(ucr, 10))
|
||||||
}
|
}
|
||||||
|
|
||||||
if teamCount, err := s.Store.Team().AnalyticsTeamCount(); err == nil {
|
if teamCount, err := s.Store.Team().AnalyticsTeamCount(); err == nil {
|
||||||
|
|||||||
@@ -136,16 +136,13 @@ func (s SqlStatusStore) ResetAll() store.StoreChannel {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlStatusStore) GetTotalActiveUsersCount() store.StoreChannel {
|
func (s SqlStatusStore) GetTotalActiveUsersCount() (int64, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
time := model.GetMillis() - (1000 * 60 * 60 * 24)
|
||||||
time := model.GetMillis() - (1000 * 60 * 60 * 24)
|
count, err := s.GetReplica().SelectInt("SELECT COUNT(UserId) FROM Status WHERE LastActivityAt > :Time", map[string]interface{}{"Time": time})
|
||||||
|
if err != nil {
|
||||||
if count, err := s.GetReplica().SelectInt("SELECT COUNT(UserId) FROM Status WHERE LastActivityAt > :Time", map[string]interface{}{"Time": time}); err != nil {
|
return count, model.NewAppError("SqlStatusStore.GetTotalActiveUsersCount", "store.sql_status.get_total_active_users_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
result.Err = model.NewAppError("SqlStatusStore.GetTotalActiveUsersCount", "store.sql_status.get_total_active_users_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
}
|
||||||
} else {
|
return count, nil
|
||||||
result.Data = count
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlStatusStore) UpdateLastActivityAt(userId string, lastActivityAt int64) store.StoreChannel {
|
func (s SqlStatusStore) UpdateLastActivityAt(userId string, lastActivityAt int64) store.StoreChannel {
|
||||||
|
|||||||
@@ -474,7 +474,7 @@ type StatusStore interface {
|
|||||||
GetOnline() ([]*model.Status, *model.AppError)
|
GetOnline() ([]*model.Status, *model.AppError)
|
||||||
GetAllFromTeam(teamId string) ([]*model.Status, *model.AppError)
|
GetAllFromTeam(teamId string) ([]*model.Status, *model.AppError)
|
||||||
ResetAll() StoreChannel
|
ResetAll() StoreChannel
|
||||||
GetTotalActiveUsersCount() StoreChannel
|
GetTotalActiveUsersCount() (int64, *model.AppError)
|
||||||
UpdateLastActivityAt(userId string, lastActivityAt int64) StoreChannel
|
UpdateLastActivityAt(userId string, lastActivityAt int64) StoreChannel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -112,19 +112,26 @@ func (_m *StatusStore) GetOnlineAway() store.StoreChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetTotalActiveUsersCount provides a mock function with given fields:
|
// GetTotalActiveUsersCount provides a mock function with given fields:
|
||||||
func (_m *StatusStore) GetTotalActiveUsersCount() store.StoreChannel {
|
func (_m *StatusStore) GetTotalActiveUsersCount() (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
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResetAll provides a mock function with given fields:
|
// ResetAll provides a mock function with given fields:
|
||||||
|
|||||||
@@ -88,10 +88,9 @@ func testActiveUserCount(t *testing.T, ss store.Store) {
|
|||||||
status := &model.Status{UserId: model.NewId(), Status: model.STATUS_ONLINE, Manual: false, LastActivityAt: model.GetMillis(), ActiveChannel: ""}
|
status := &model.Status{UserId: model.NewId(), Status: model.STATUS_ONLINE, Manual: false, LastActivityAt: model.GetMillis(), ActiveChannel: ""}
|
||||||
require.Nil(t, ss.Status().SaveOrUpdate(status))
|
require.Nil(t, ss.Status().SaveOrUpdate(status))
|
||||||
|
|
||||||
if result := <-ss.Status().GetTotalActiveUsersCount(); result.Err != nil {
|
if count, err := ss.Status().GetTotalActiveUsersCount(); err != nil {
|
||||||
t.Fatal(result.Err)
|
t.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
count := result.Data.(int64)
|
|
||||||
require.True(t, count > 0, "expected count > 0, got %d", count)
|
require.True(t, count > 0, "expected count > 0, got %d", count)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user