MM-16565 Migrate "User.GetNewUsersForTeam" to Sync by default (#11405)

* initial code

* rename result var to user

* rename var to users
Этот коммит содержится в:
Alex Sahin
2019-06-26 14:35:02 +01:00
коммит произвёл Lev
родитель 5acb0ad227
Коммит abaf0221b6
5 изменённых файлов: 49 добавлений и 46 удалений

Просмотреть файл

@@ -324,12 +324,10 @@ func (a *App) GetRecentlyActiveUsersForTeamPage(teamId string, page, perPage int
} }
func (a *App) GetNewUsersForTeamPage(teamId string, page, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) { func (a *App) GetNewUsersForTeamPage(teamId string, page, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) {
var users []*model.User users, err := a.Srv.Store.User().GetNewUsersForTeam(teamId, page*perPage, perPage, viewRestrictions)
result := <-a.Srv.Store.User().GetNewUsersForTeam(teamId, page*perPage, perPage, viewRestrictions) if err != nil {
if result.Err != nil { return nil, err
return nil, result.Err
} }
users = result.Data.([]*model.User)
return a.sanitizeProfiles(users, asAdmin), nil return a.sanitizeProfiles(users, asAdmin), nil
} }

Просмотреть файл

@@ -824,34 +824,30 @@ func (us SqlUserStore) GetRecentlyActiveUsersForTeam(teamId string, offset, limi
}) })
} }
func (us SqlUserStore) GetNewUsersForTeam(teamId string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) store.StoreChannel { func (us SqlUserStore) GetNewUsersForTeam(teamId string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) {
return store.Do(func(result *store.StoreResult) { query := us.usersQuery.
query := us.usersQuery. Join("TeamMembers tm ON (tm.UserId = u.Id AND tm.TeamId = ?)", teamId).
Join("TeamMembers tm ON (tm.UserId = u.Id AND tm.TeamId = ?)", teamId). OrderBy("u.CreateAt DESC").
OrderBy("u.CreateAt DESC"). OrderBy("u.Username ASC").
OrderBy("u.Username ASC"). Offset(uint64(offset)).Limit(uint64(limit))
Offset(uint64(offset)).Limit(uint64(limit))
query = applyViewRestrictionsFilter(query, viewRestrictions, true) query = applyViewRestrictionsFilter(query, viewRestrictions, true)
queryString, args, err := query.ToSql() queryString, args, err := query.ToSql()
if err != nil { if err != nil {
result.Err = model.NewAppError("SqlUserStore.GetNewUsersForTeam", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError) return nil, model.NewAppError("SqlUserStore.GetNewUsersForTeam", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
return }
}
var users []*model.User var users []*model.User
if _, err := us.GetReplica().Select(&users, queryString, args...); err != nil { if _, err := us.GetReplica().Select(&users, queryString, args...); err != nil {
result.Err = model.NewAppError("SqlUserStore.GetNewUsersForTeam", "store.sql_user.get_new_users.app_error", nil, err.Error(), http.StatusInternalServerError) return nil, model.NewAppError("SqlUserStore.GetNewUsersForTeam", "store.sql_user.get_new_users.app_error", nil, err.Error(), http.StatusInternalServerError)
return }
}
for _, u := range users { for _, u := range users {
u.Sanitize(map[string]bool{}) u.Sanitize(map[string]bool{})
} }
result.Data = users return users, nil
})
} }
func (us SqlUserStore) GetProfileByIds(userIds []string, allowFromCache bool, viewRestrictions *model.ViewUsersRestrictions) store.StoreChannel { func (us SqlUserStore) GetProfileByIds(userIds []string, allowFromCache bool, viewRestrictions *model.ViewUsersRestrictions) store.StoreChannel {

Просмотреть файл

@@ -287,7 +287,7 @@ type UserStore interface {
GetUnreadCountForChannel(userId string, channelId string) StoreChannel GetUnreadCountForChannel(userId string, channelId string) StoreChannel
GetAnyUnreadPostCountForChannel(userId string, channelId string) StoreChannel GetAnyUnreadPostCountForChannel(userId string, channelId string) StoreChannel
GetRecentlyActiveUsersForTeam(teamId string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) StoreChannel GetRecentlyActiveUsersForTeam(teamId string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) StoreChannel
GetNewUsersForTeam(teamId string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) StoreChannel GetNewUsersForTeam(teamId string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
Search(teamId string, term string, options *model.UserSearchOptions) StoreChannel Search(teamId string, term string, options *model.UserSearchOptions) StoreChannel
SearchNotInTeam(notInTeamId string, term string, options *model.UserSearchOptions) StoreChannel SearchNotInTeam(notInTeamId string, term string, options *model.UserSearchOptions) StoreChannel
SearchInChannel(channelId string, term string, options *model.UserSearchOptions) StoreChannel SearchInChannel(channelId string, term string, options *model.UserSearchOptions) StoreChannel

Просмотреть файл

@@ -382,19 +382,28 @@ func (_m *UserStore) GetForLogin(loginId string, allowSignInWithUsername bool, a
} }
// GetNewUsersForTeam provides a mock function with given fields: teamId, offset, limit, viewRestrictions // GetNewUsersForTeam provides a mock function with given fields: teamId, offset, limit, viewRestrictions
func (_m *UserStore) GetNewUsersForTeam(teamId string, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) store.StoreChannel { func (_m *UserStore) GetNewUsersForTeam(teamId string, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) {
ret := _m.Called(teamId, offset, limit, viewRestrictions) ret := _m.Called(teamId, offset, limit, viewRestrictions)
var r0 store.StoreChannel var r0 []*model.User
if rf, ok := ret.Get(0).(func(string, int, int, *model.ViewUsersRestrictions) store.StoreChannel); ok { if rf, ok := ret.Get(0).(func(string, int, int, *model.ViewUsersRestrictions) []*model.User); ok {
r0 = rf(teamId, offset, limit, viewRestrictions) r0 = rf(teamId, offset, limit, viewRestrictions)
} else { } else {
if ret.Get(0) != nil { if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel) r0 = ret.Get(0).([]*model.User)
} }
} }
return r0 var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, int, int, *model.ViewUsersRestrictions) *model.AppError); ok {
r1 = rf(teamId, offset, limit, viewRestrictions)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
} }
// GetProfileByGroupChannelIdsForUser provides a mock function with given fields: userId, channelIds // GetProfileByGroupChannelIdsForUser provides a mock function with given fields: userId, channelIds

Просмотреть файл

@@ -2039,37 +2039,37 @@ func testUserStoreGetNewUsersForTeam(t *testing.T, ss store.Store) {
store.Must(ss.Team().SaveMember(&model.TeamMember{TeamId: teamId2, UserId: u4.Id}, -1)) store.Must(ss.Team().SaveMember(&model.TeamMember{TeamId: teamId2, UserId: u4.Id}, -1))
t.Run("get team 1, offset 0, limit 100", func(t *testing.T) { t.Run("get team 1, offset 0, limit 100", func(t *testing.T) {
result := <-ss.User().GetNewUsersForTeam(teamId, 0, 100, nil) result, err := ss.User().GetNewUsersForTeam(teamId, 0, 100, nil)
require.Nil(t, result.Err) require.Nil(t, err)
assert.Equal(t, []*model.User{ assert.Equal(t, []*model.User{
sanitized(u3), sanitized(u3),
sanitized(u2), sanitized(u2),
sanitized(u1), sanitized(u1),
}, result.Data.([]*model.User)) }, result)
}) })
t.Run("get team 1, offset 0, limit 1", func(t *testing.T) { t.Run("get team 1, offset 0, limit 1", func(t *testing.T) {
result := <-ss.User().GetNewUsersForTeam(teamId, 0, 1, nil) result, err := ss.User().GetNewUsersForTeam(teamId, 0, 1, nil)
require.Nil(t, result.Err) require.Nil(t, err)
assert.Equal(t, []*model.User{ assert.Equal(t, []*model.User{
sanitized(u3), sanitized(u3),
}, result.Data.([]*model.User)) }, result)
}) })
t.Run("get team 1, offset 2, limit 1", func(t *testing.T) { t.Run("get team 1, offset 2, limit 1", func(t *testing.T) {
result := <-ss.User().GetNewUsersForTeam(teamId, 2, 1, nil) result, err := ss.User().GetNewUsersForTeam(teamId, 2, 1, nil)
require.Nil(t, result.Err) require.Nil(t, err)
assert.Equal(t, []*model.User{ assert.Equal(t, []*model.User{
sanitized(u1), sanitized(u1),
}, result.Data.([]*model.User)) }, result)
}) })
t.Run("get team 2, offset 0, limit 100", func(t *testing.T) { t.Run("get team 2, offset 0, limit 100", func(t *testing.T) {
result := <-ss.User().GetNewUsersForTeam(teamId2, 0, 100, nil) result, err := ss.User().GetNewUsersForTeam(teamId2, 0, 100, nil)
require.Nil(t, result.Err) require.Nil(t, err)
assert.Equal(t, []*model.User{ assert.Equal(t, []*model.User{
sanitized(u4), sanitized(u4),
}, result.Data.([]*model.User)) }, result)
}) })
} }