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))
|
||||
}
|
||||
|
||||
if ucr := <-s.Store.Status().GetTotalActiveUsersCount(); ucr.Err == nil {
|
||||
v.Set(PROP_SECURITY_ACTIVE_USER_COUNT, strconv.FormatInt(ucr.Data.(int64), 10))
|
||||
if ucr, err := s.Store.Status().GetTotalActiveUsersCount(); err == nil {
|
||||
v.Set(PROP_SECURITY_ACTIVE_USER_COUNT, strconv.FormatInt(ucr, 10))
|
||||
}
|
||||
|
||||
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 {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
time := model.GetMillis() - (1000 * 60 * 60 * 24)
|
||||
|
||||
if count, err := s.GetReplica().SelectInt("SELECT COUNT(UserId) FROM Status WHERE LastActivityAt > :Time", map[string]interface{}{"Time": time}); err != nil {
|
||||
result.Err = model.NewAppError("SqlStatusStore.GetTotalActiveUsersCount", "store.sql_status.get_total_active_users_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
} else {
|
||||
result.Data = count
|
||||
}
|
||||
})
|
||||
func (s SqlStatusStore) GetTotalActiveUsersCount() (int64, *model.AppError) {
|
||||
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 {
|
||||
return count, model.NewAppError("SqlStatusStore.GetTotalActiveUsersCount", "store.sql_status.get_total_active_users_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (s SqlStatusStore) UpdateLastActivityAt(userId string, lastActivityAt int64) store.StoreChannel {
|
||||
|
||||
@@ -474,7 +474,7 @@ type StatusStore interface {
|
||||
GetOnline() ([]*model.Status, *model.AppError)
|
||||
GetAllFromTeam(teamId string) ([]*model.Status, *model.AppError)
|
||||
ResetAll() StoreChannel
|
||||
GetTotalActiveUsersCount() StoreChannel
|
||||
GetTotalActiveUsersCount() (int64, *model.AppError)
|
||||
UpdateLastActivityAt(userId string, lastActivityAt int64) StoreChannel
|
||||
}
|
||||
|
||||
|
||||
@@ -112,19 +112,26 @@ func (_m *StatusStore) GetOnlineAway() store.StoreChannel {
|
||||
}
|
||||
|
||||
// GetTotalActiveUsersCount provides a mock function with given fields:
|
||||
func (_m *StatusStore) GetTotalActiveUsersCount() store.StoreChannel {
|
||||
func (_m *StatusStore) GetTotalActiveUsersCount() (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
|
||||
}
|
||||
|
||||
// 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: ""}
|
||||
require.Nil(t, ss.Status().SaveOrUpdate(status))
|
||||
|
||||
if result := <-ss.Status().GetTotalActiveUsersCount(); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
if count, err := ss.Status().GetTotalActiveUsersCount(); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
count := result.Data.(int64)
|
||||
require.True(t, count > 0, "expected count > 0, got %d", count)
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user