Migrates Channel.GetMembersForUser to sync by default (#11236)
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
1f6aedcdf3
Коммит
d17bdc6764
@@ -1301,11 +1301,7 @@ func (a *App) GetChannelMembersByIds(channelId string, userIds []string) (*model
|
||||
}
|
||||
|
||||
func (a *App) GetChannelMembersForUser(teamId string, userId string) (*model.ChannelMembers, *model.AppError) {
|
||||
result := <-a.Srv.Store.Channel().GetMembersForUser(teamId, userId)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
return result.Data.(*model.ChannelMembers), nil
|
||||
return a.Srv.Store.Channel().GetMembersForUser(teamId, userId)
|
||||
}
|
||||
|
||||
func (a *App) GetChannelMembersForUserWithPagination(teamId, userId string, page, perPage int) ([]*model.ChannelMember, *model.AppError) {
|
||||
|
||||
@@ -152,19 +152,17 @@ func (job *EmailBatchingJob) checkPendingNotifications(now time.Time, handler fu
|
||||
|
||||
// if the user has viewed any channels in this team since the notification was queued, delete
|
||||
// all queued notifications
|
||||
result := <-job.server.Store.Channel().GetMembersForUser(inspectedTeamNames[notification.teamName], userId)
|
||||
if result.Err != nil {
|
||||
mlog.Error(fmt.Sprint("Unable to find ChannelMembers for user", result.Err))
|
||||
channelMembers, err := job.server.Store.Channel().GetMembersForUser(inspectedTeamNames[notification.teamName], userId)
|
||||
if err != nil {
|
||||
mlog.Error(fmt.Sprint("Unable to find ChannelMembers for user", err))
|
||||
continue
|
||||
}
|
||||
|
||||
if channelMembers, ok := result.Data.(*model.ChannelMembers); ok {
|
||||
for _, channelMember := range *channelMembers {
|
||||
if channelMember.LastViewedAt >= batchStartTime {
|
||||
mlog.Debug(fmt.Sprintf("Deleted notifications for user %s", userId), mlog.String("user_id", userId))
|
||||
delete(job.pendingNotifications, userId)
|
||||
break
|
||||
}
|
||||
for _, channelMember := range *channelMembers {
|
||||
if channelMember.LastViewedAt >= batchStartTime {
|
||||
mlog.Debug(fmt.Sprintf("Deleted notifications for user %s", userId), mlog.String("user_id", userId))
|
||||
delete(job.pendingNotifications, userId)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2198,13 +2198,13 @@ func (a *App) GetViewUsersRestrictionsForTeam(userId string, teamId string) ([]s
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
result := <-a.Srv.Store.Channel().GetMembersForUser(teamId, userId)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
members, err := a.Srv.Store.Channel().GetMembersForUser(teamId, userId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
channelIds := []string{}
|
||||
for _, membership := range *result.Data.(*model.ChannelMembers) {
|
||||
for _, membership := range *members {
|
||||
channelIds = append(channelIds, membership.ChannelId)
|
||||
}
|
||||
|
||||
|
||||
@@ -1904,18 +1904,15 @@ func (s SqlChannelStore) AnalyticsDeletedTypeCount(teamId string, channelType st
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetMembersForUser(teamId string, userId string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
var dbMembers channelMemberWithSchemeRolesList
|
||||
_, err := s.GetReplica().Select(&dbMembers, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelMembers.UserId = :UserId", map[string]interface{}{"TeamId": teamId, "UserId": userId})
|
||||
func (s SqlChannelStore) GetMembersForUser(teamId string, userId string) (*model.ChannelMembers, *model.AppError) {
|
||||
var dbMembers channelMemberWithSchemeRolesList
|
||||
_, err := s.GetReplica().Select(&dbMembers, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelMembers.UserId = :UserId", map[string]interface{}{"TeamId": teamId, "UserId": userId})
|
||||
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlChannelStore.GetMembersForUser", "store.sql_channel.get_members.app_error", nil, "teamId="+teamId+", userId="+userId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlChannelStore.GetMembersForUser", "store.sql_channel.get_members.app_error", nil, "teamId="+teamId+", userId="+userId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
result.Data = dbMembers.ToModel()
|
||||
})
|
||||
return dbMembers.ToModel(), nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetMembersForUserWithPagination(teamId, userId string, page, perPage int) store.StoreChannel {
|
||||
|
||||
@@ -179,7 +179,7 @@ type ChannelStore interface {
|
||||
UpdateLastViewedAt(channelIds []string, userId string) StoreChannel
|
||||
IncrementMentionCount(channelId string, userId string) *model.AppError
|
||||
AnalyticsTypeCount(teamId string, channelType string) (int64, *model.AppError)
|
||||
GetMembersForUser(teamId string, userId string) StoreChannel
|
||||
GetMembersForUser(teamId string, userId string) (*model.ChannelMembers, *model.AppError)
|
||||
GetMembersForUserWithPagination(teamId, userId string, page, perPage int) StoreChannel
|
||||
AutocompleteInTeam(teamId string, term string, includeDeleted bool) (*model.ChannelList, *model.AppError)
|
||||
AutocompleteInTeamForSearch(teamId string, userId string, term string, includeDeleted bool) StoreChannel
|
||||
|
||||
@@ -1597,8 +1597,8 @@ func testChannelStoreGetMembersForUser(t *testing.T, ss store.Store) {
|
||||
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||
store.Must(ss.Channel().SaveMember(&m2))
|
||||
|
||||
cresult := <-ss.Channel().GetMembersForUser(o1.TeamId, m1.UserId)
|
||||
members := cresult.Data.(*model.ChannelMembers)
|
||||
members, err := ss.Channel().GetMembersForUser(o1.TeamId, m1.UserId)
|
||||
require.Nil(t, err)
|
||||
|
||||
// no unread messages
|
||||
if len(*members) != 2 {
|
||||
|
||||
@@ -855,19 +855,28 @@ func (_m *ChannelStore) GetMembersByIds(channelId string, userIds []string) (*mo
|
||||
}
|
||||
|
||||
// GetMembersForUser provides a mock function with given fields: teamId, userId
|
||||
func (_m *ChannelStore) GetMembersForUser(teamId string, userId string) store.StoreChannel {
|
||||
func (_m *ChannelStore) GetMembersForUser(teamId string, userId string) (*model.ChannelMembers, *model.AppError) {
|
||||
ret := _m.Called(teamId, userId)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string, string) store.StoreChannel); ok {
|
||||
var r0 *model.ChannelMembers
|
||||
if rf, ok := ret.Get(0).(func(string, string) *model.ChannelMembers); ok {
|
||||
r0 = rf(teamId, userId)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
r0 = ret.Get(0).(*model.ChannelMembers)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok {
|
||||
r1 = rf(teamId, userId)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetMembersForUserWithPagination provides a mock function with given fields: teamId, userId, page, perPage
|
||||
|
||||
Ссылка в новой задаче
Block a user