mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Migrate Channel.GetAllChannelMembersForUser to Sync by default (#11234)
* Migrate Channel.GetAllChannelMembersForUser to Sync by default * fix gofmt for sqlstore/channel_store.go
This commit is contained in:
committed by
Jesús Espino
parent
df9af66a28
commit
00bb39b2bd
@@ -40,11 +40,10 @@ func (a *App) SessionHasPermissionToChannel(session model.Session, channelId str
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
cmc := a.Srv.Store.Channel().GetAllChannelMembersForUser(session.UserId, true, true)
|
ids, err := a.Srv.Store.Channel().GetAllChannelMembersForUser(session.UserId, true, true)
|
||||||
|
|
||||||
var channelRoles []string
|
var channelRoles []string
|
||||||
if cmcresult := <-cmc; cmcresult.Err == nil {
|
if err == nil {
|
||||||
ids := cmcresult.Data.(map[string]string)
|
|
||||||
if roles, ok := ids[channelId]; ok {
|
if roles, ok := ids[channelId]; ok {
|
||||||
channelRoles = strings.Fields(roles)
|
channelRoles = strings.Fields(roles)
|
||||||
if a.RolesGrantPermission(channelRoles, permission.Id) {
|
if a.RolesGrantPermission(channelRoles, permission.Id) {
|
||||||
|
|||||||
16
app/user.go
16
app/user.go
@@ -199,13 +199,13 @@ func (a *App) indexUser(user *model.User) *model.AppError {
|
|||||||
userTeamsIds = append(userTeamsIds, team.Id)
|
userTeamsIds = append(userTeamsIds, team.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
userChannelMembers := <-a.Srv.Store.Channel().GetAllChannelMembersForUser(user.Id, false, true)
|
userChannelMembers, err := a.Srv.Store.Channel().GetAllChannelMembersForUser(user.Id, false, true)
|
||||||
if userChannelMembers.Err != nil {
|
if err != nil {
|
||||||
return userChannelMembers.Err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
userChannelsIds := []string{}
|
userChannelsIds := []string{}
|
||||||
for channelId := range userChannelMembers.Data.(map[string]string) {
|
for channelId := range userChannelMembers {
|
||||||
userChannelsIds = append(userChannelsIds, channelId)
|
userChannelsIds = append(userChannelsIds, channelId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2167,13 +2167,13 @@ func (a *App) GetViewUsersRestrictions(userId string) (*model.ViewUsersRestricti
|
|||||||
return &model.ViewUsersRestrictions{Teams: teamIdsWithPermission}, nil
|
return &model.ViewUsersRestrictions{Teams: teamIdsWithPermission}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
userChannelMembers := <-a.Srv.Store.Channel().GetAllChannelMembersForUser(userId, true, true)
|
userChannelMembers, err := a.Srv.Store.Channel().GetAllChannelMembersForUser(userId, true, true)
|
||||||
if userChannelMembers.Err != nil {
|
if err != nil {
|
||||||
return nil, userChannelMembers.Err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
channelIds := []string{}
|
channelIds := []string{}
|
||||||
for channelId := range userChannelMembers.Data.(map[string]string) {
|
for channelId := range userChannelMembers {
|
||||||
channelIds = append(channelIds, channelId)
|
channelIds = append(channelIds, channelId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -336,12 +336,12 @@ func (webCon *WebConn) ShouldSendEvent(msg *model.WebSocketEvent) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if webCon.AllChannelMembers == nil {
|
if webCon.AllChannelMembers == nil {
|
||||||
result := <-webCon.App.Srv.Store.Channel().GetAllChannelMembersForUser(webCon.UserId, true, false)
|
result, err := webCon.App.Srv.Store.Channel().GetAllChannelMembersForUser(webCon.UserId, true, false)
|
||||||
if result.Err != nil {
|
if err != nil {
|
||||||
mlog.Error("webhub.shouldSendEvent: " + result.Err.Error())
|
mlog.Error("webhub.shouldSendEvent: " + err.Error())
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
webCon.AllChannelMembers = result.Data.(map[string]string)
|
webCon.AllChannelMembers = result
|
||||||
webCon.LastAllChannelMembersTime = model.GetMillis()
|
webCon.LastAllChannelMembersTime = model.GetMillis()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1465,13 +1465,12 @@ func (s SqlChannelStore) IsUserInChannelUseCache(userId string, channelId string
|
|||||||
s.metrics.IncrementMemCacheMissCounter("All Channel Members for User")
|
s.metrics.IncrementMemCacheMissCounter("All Channel Members for User")
|
||||||
}
|
}
|
||||||
|
|
||||||
result := <-s.GetAllChannelMembersForUser(userId, true, false)
|
ids, err := s.GetAllChannelMembersForUser(userId, true, false)
|
||||||
if result.Err != nil {
|
if err != nil {
|
||||||
mlog.Error("SqlChannelStore.IsUserInChannelUseCache: " + result.Err.Error())
|
mlog.Error("SqlChannelStore.IsUserInChannelUseCache: " + err.Error())
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
ids := result.Data.(map[string]string)
|
|
||||||
if _, ok := ids[channelId]; ok {
|
if _, ok := ids[channelId]; ok {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -1512,33 +1511,32 @@ func (s SqlChannelStore) GetMemberForPost(postId string, userId string) (*model.
|
|||||||
return dbMember.ToModel(), nil
|
return dbMember.ToModel(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlChannelStore) GetAllChannelMembersForUser(userId string, allowFromCache bool, includeDeleted bool) store.StoreChannel {
|
func (s SqlChannelStore) GetAllChannelMembersForUser(userId string, allowFromCache bool, includeDeleted bool) (map[string]string, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
cache_key := userId
|
||||||
cache_key := userId
|
if includeDeleted {
|
||||||
if includeDeleted {
|
cache_key += "_deleted"
|
||||||
cache_key += "_deleted"
|
}
|
||||||
}
|
if allowFromCache {
|
||||||
if allowFromCache {
|
if cacheItem, ok := allChannelMembersForUserCache.Get(cache_key); ok {
|
||||||
if cacheItem, ok := allChannelMembersForUserCache.Get(cache_key); ok {
|
if s.metrics != nil {
|
||||||
if s.metrics != nil {
|
s.metrics.IncrementMemCacheHitCounter("All Channel Members for User")
|
||||||
s.metrics.IncrementMemCacheHitCounter("All Channel Members for User")
|
|
||||||
}
|
|
||||||
result.Data = cacheItem.(map[string]string)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
ids := cacheItem.(map[string]string)
|
||||||
|
return ids, nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if s.metrics != nil {
|
if s.metrics != nil {
|
||||||
s.metrics.IncrementMemCacheMissCounter("All Channel Members for User")
|
s.metrics.IncrementMemCacheMissCounter("All Channel Members for User")
|
||||||
}
|
}
|
||||||
|
|
||||||
var deletedClause string
|
var deletedClause string
|
||||||
if !includeDeleted {
|
if !includeDeleted {
|
||||||
deletedClause = "Channels.DeleteAt = 0 AND"
|
deletedClause = "Channels.DeleteAt = 0 AND"
|
||||||
}
|
}
|
||||||
|
|
||||||
var data allChannelMembers
|
var data allChannelMembers
|
||||||
_, err := s.GetReplica().Select(&data, `
|
_, err := s.GetReplica().Select(&data, `
|
||||||
SELECT
|
SELECT
|
||||||
ChannelMembers.ChannelId, ChannelMembers.Roles,
|
ChannelMembers.ChannelId, ChannelMembers.Roles,
|
||||||
ChannelMembers.SchemeGuest, ChannelMembers.SchemeUser, ChannelMembers.SchemeAdmin,
|
ChannelMembers.SchemeGuest, ChannelMembers.SchemeUser, ChannelMembers.SchemeAdmin,
|
||||||
@@ -1562,18 +1560,16 @@ func (s SqlChannelStore) GetAllChannelMembersForUser(userId string, allowFromCac
|
|||||||
`+deletedClause+`
|
`+deletedClause+`
|
||||||
ChannelMembers.UserId = :UserId`, map[string]interface{}{"UserId": userId})
|
ChannelMembers.UserId = :UserId`, map[string]interface{}{"UserId": userId})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlChannelStore.GetAllChannelMembersForUser", "store.sql_channel.get_channels.get.app_error", nil, "userId="+userId+", err="+err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("SqlChannelStore.GetAllChannelMembersForUser", "store.sql_channel.get_channels.get.app_error", nil, "userId="+userId+", err="+err.Error(), http.StatusInternalServerError)
|
||||||
return
|
}
|
||||||
}
|
|
||||||
|
|
||||||
ids := data.ToMapStringString()
|
ids := data.ToMapStringString()
|
||||||
result.Data = ids
|
|
||||||
|
|
||||||
if allowFromCache {
|
if allowFromCache {
|
||||||
allChannelMembersForUserCache.AddWithExpiresInSecs(cache_key, ids, ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_SEC)
|
allChannelMembersForUserCache.AddWithExpiresInSecs(cache_key, ids, ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_SEC)
|
||||||
}
|
}
|
||||||
})
|
return ids, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlChannelStore) InvalidateCacheForChannelMembersNotifyProps(channelId string) {
|
func (s SqlChannelStore) InvalidateCacheForChannelMembersNotifyProps(channelId string) {
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ type ChannelStore interface {
|
|||||||
GetMembers(channelId string, offset, limit int) (*model.ChannelMembers, *model.AppError)
|
GetMembers(channelId string, offset, limit int) (*model.ChannelMembers, *model.AppError)
|
||||||
GetMember(channelId string, userId string) (*model.ChannelMember, *model.AppError)
|
GetMember(channelId string, userId string) (*model.ChannelMember, *model.AppError)
|
||||||
GetChannelMembersTimezones(channelId string) ([]model.StringMap, *model.AppError)
|
GetChannelMembersTimezones(channelId string) ([]model.StringMap, *model.AppError)
|
||||||
GetAllChannelMembersForUser(userId string, allowFromCache bool, includeDeleted bool) StoreChannel
|
GetAllChannelMembersForUser(userId string, allowFromCache bool, includeDeleted bool) (map[string]string, *model.AppError)
|
||||||
InvalidateAllChannelMembersForUser(userId string)
|
InvalidateAllChannelMembersForUser(userId string)
|
||||||
IsUserInChannelUseCache(userId string, channelId string) bool
|
IsUserInChannelUseCache(userId string, channelId string) bool
|
||||||
GetAllChannelMembersNotifyPropsForChannel(channelId string, allowFromCache bool) (map[string]model.StringMap, *model.AppError)
|
GetAllChannelMembersNotifyPropsForChannel(channelId string, allowFromCache bool) (map[string]model.StringMap, *model.AppError)
|
||||||
|
|||||||
@@ -1046,20 +1046,17 @@ func testChannelStoreGetChannels(t *testing.T, ss store.Store) {
|
|||||||
t.Fatal("missing channel")
|
t.Fatal("missing channel")
|
||||||
}
|
}
|
||||||
|
|
||||||
acresult := <-ss.Channel().GetAllChannelMembersForUser(m1.UserId, false, false)
|
ids, _ := ss.Channel().GetAllChannelMembersForUser(m1.UserId, false, false)
|
||||||
ids := acresult.Data.(map[string]string)
|
|
||||||
if _, ok := ids[o1.Id]; !ok {
|
if _, ok := ids[o1.Id]; !ok {
|
||||||
t.Fatal("missing channel")
|
t.Fatal("missing channel")
|
||||||
}
|
}
|
||||||
|
|
||||||
acresult2 := <-ss.Channel().GetAllChannelMembersForUser(m1.UserId, true, false)
|
ids2, _ := ss.Channel().GetAllChannelMembersForUser(m1.UserId, true, false)
|
||||||
ids2 := acresult2.Data.(map[string]string)
|
|
||||||
if _, ok := ids2[o1.Id]; !ok {
|
if _, ok := ids2[o1.Id]; !ok {
|
||||||
t.Fatal("missing channel")
|
t.Fatal("missing channel")
|
||||||
}
|
}
|
||||||
|
|
||||||
acresult3 := <-ss.Channel().GetAllChannelMembersForUser(m1.UserId, true, false)
|
ids3, _ := ss.Channel().GetAllChannelMembersForUser(m1.UserId, true, false)
|
||||||
ids3 := acresult3.Data.(map[string]string)
|
|
||||||
if _, ok := ids3[o1.Id]; !ok {
|
if _, ok := ids3[o1.Id]; !ok {
|
||||||
t.Fatal("missing channel")
|
t.Fatal("missing channel")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -222,19 +222,28 @@ func (_m *ChannelStore) GetAll(teamId string) ([]*model.Channel, *model.AppError
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetAllChannelMembersForUser provides a mock function with given fields: userId, allowFromCache, includeDeleted
|
// GetAllChannelMembersForUser provides a mock function with given fields: userId, allowFromCache, includeDeleted
|
||||||
func (_m *ChannelStore) GetAllChannelMembersForUser(userId string, allowFromCache bool, includeDeleted bool) store.StoreChannel {
|
func (_m *ChannelStore) GetAllChannelMembersForUser(userId string, allowFromCache bool, includeDeleted bool) (map[string]string, *model.AppError) {
|
||||||
ret := _m.Called(userId, allowFromCache, includeDeleted)
|
ret := _m.Called(userId, allowFromCache, includeDeleted)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 map[string]string
|
||||||
if rf, ok := ret.Get(0).(func(string, bool, bool) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string, bool, bool) map[string]string); ok {
|
||||||
r0 = rf(userId, allowFromCache, includeDeleted)
|
r0 = rf(userId, allowFromCache, includeDeleted)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
r0 = ret.Get(0).(map[string]string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
var r1 *model.AppError
|
||||||
|
if rf, ok := ret.Get(1).(func(string, bool, bool) *model.AppError); ok {
|
||||||
|
r1 = rf(userId, allowFromCache, includeDeleted)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAllChannelMembersNotifyPropsForChannel provides a mock function with given fields: channelId, allowFromCache
|
// GetAllChannelMembersNotifyPropsForChannel provides a mock function with given fields: channelId, allowFromCache
|
||||||
|
|||||||
Reference in New Issue
Block a user