[MM-16330] Migrate "Channel.GetForPost" to Sync by default (#11199)
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
209f70e80b
Коммит
5c32f92413
@@ -75,8 +75,7 @@ func (a *App) SessionHasPermissionToChannelByPost(session model.Session, postId
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := <-a.Srv.Store.Channel().GetForPost(postId); result.Err == nil {
|
if channel, err := a.Srv.Store.Channel().GetForPost(postId); err == nil {
|
||||||
channel := result.Data.(*model.Channel)
|
|
||||||
if channel.TeamId != "" {
|
if channel.TeamId != "" {
|
||||||
return a.SessionHasPermissionToTeam(session, channel.TeamId, permission)
|
return a.SessionHasPermissionToTeam(session, channel.TeamId, permission)
|
||||||
}
|
}
|
||||||
@@ -175,8 +174,7 @@ func (a *App) HasPermissionToChannelByPost(askingUserId string, postId string, p
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := <-a.Srv.Store.Channel().GetForPost(postId); result.Err == nil {
|
if channel, err := a.Srv.Store.Channel().GetForPost(postId); err == nil {
|
||||||
channel := result.Data.(*model.Channel)
|
|
||||||
return a.HasPermissionToTeam(askingUserId, channel.TeamId, permission)
|
return a.HasPermissionToTeam(askingUserId, channel.TeamId, permission)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,12 @@ func (a *App) DoPostActionWithCookie(postId, actionId, userId, selectedOption st
|
|||||||
close(pchan)
|
close(pchan)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
cchan := a.Srv.Store.Channel().GetForPost(postId)
|
cchan := make(chan store.StoreResult, 1)
|
||||||
|
go func() {
|
||||||
|
channel, err := a.Srv.Store.Channel().GetForPost(postId)
|
||||||
|
cchan <- store.StoreResult{Data: channel, Err: err}
|
||||||
|
close(cchan)
|
||||||
|
}()
|
||||||
|
|
||||||
result := <-pchan
|
result := <-pchan
|
||||||
if result.Err != nil {
|
if result.Err != nil {
|
||||||
|
|||||||
14
app/post.go
14
app/post.go
@@ -341,11 +341,11 @@ func (a *App) FillInPostProps(post *model.Post, channel *model.Channel) *model.A
|
|||||||
|
|
||||||
if len(channelMentions) > 0 {
|
if len(channelMentions) > 0 {
|
||||||
if channel == nil {
|
if channel == nil {
|
||||||
result := <-a.Srv.Store.Channel().GetForPost(post.Id)
|
postChannel, err := a.Srv.Store.Channel().GetForPost(post.Id)
|
||||||
if result.Err != nil {
|
if err != nil {
|
||||||
return model.NewAppError("FillInPostProps", "api.context.invalid_param.app_error", map[string]interface{}{"Name": "post.channel_id"}, result.Err.Error(), http.StatusBadRequest)
|
return model.NewAppError("FillInPostProps", "api.context.invalid_param.app_error", map[string]interface{}{"Name": "post.channel_id"}, err.Error(), http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
channel = result.Data.(*model.Channel)
|
channel = postChannel
|
||||||
}
|
}
|
||||||
|
|
||||||
mentionedChannels, err := a.GetChannelsByNames(channelMentions, channel.TeamId)
|
mentionedChannels, err := a.GetChannelsByNames(channelMentions, channel.TeamId)
|
||||||
@@ -552,12 +552,12 @@ func (a *App) UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model
|
|||||||
|
|
||||||
if a.IsESIndexingEnabled() {
|
if a.IsESIndexingEnabled() {
|
||||||
a.Srv.Go(func() {
|
a.Srv.Go(func() {
|
||||||
rchannel := <-a.Srv.Store.Channel().GetForPost(rpost.Id)
|
channel, chanErr := a.Srv.Store.Channel().GetForPost(rpost.Id)
|
||||||
if rchannel.Err != nil {
|
if chanErr != nil {
|
||||||
mlog.Error(fmt.Sprintf("Couldn't get channel %v for post %v for Elasticsearch indexing.", rpost.ChannelId, rpost.Id))
|
mlog.Error(fmt.Sprintf("Couldn't get channel %v for post %v for Elasticsearch indexing.", rpost.ChannelId, rpost.Id))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := a.Elasticsearch.IndexPost(rpost, rchannel.Data.(*model.Channel).TeamId); err != nil {
|
if err := a.Elasticsearch.IndexPost(rpost, channel.TeamId); err != nil {
|
||||||
mlog.Error("Encountered error indexing post", mlog.String("post_id", post.Id), mlog.Err(err))
|
mlog.Error("Encountered error indexing post", mlog.String("post_id", post.Id), mlog.Err(err))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1857,25 +1857,22 @@ func (s SqlChannelStore) GetChannelsByIds(channelIds []string) ([]*model.Channel
|
|||||||
return channels, nil
|
return channels, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlChannelStore) GetForPost(postId string) store.StoreChannel {
|
func (s SqlChannelStore) GetForPost(postId string) (*model.Channel, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
channel := &model.Channel{}
|
||||||
channel := &model.Channel{}
|
if err := s.GetReplica().SelectOne(
|
||||||
if err := s.GetReplica().SelectOne(
|
channel,
|
||||||
channel,
|
`SELECT
|
||||||
`SELECT
|
Channels.*
|
||||||
Channels.*
|
FROM
|
||||||
FROM
|
Channels,
|
||||||
Channels,
|
Posts
|
||||||
Posts
|
WHERE
|
||||||
WHERE
|
Channels.Id = Posts.ChannelId
|
||||||
Channels.Id = Posts.ChannelId
|
AND Posts.Id = :PostId`, map[string]interface{}{"PostId": postId}); err != nil {
|
||||||
AND Posts.Id = :PostId`, map[string]interface{}{"PostId": postId}); err != nil {
|
return nil, model.NewAppError("SqlChannelStore.GetForPost", "store.sql_channel.get_for_post.app_error", nil, "postId="+postId+", err="+err.Error(), http.StatusInternalServerError)
|
||||||
result.Err = model.NewAppError("SqlChannelStore.GetForPost", "store.sql_channel.get_for_post.app_error", nil, "postId="+postId+", err="+err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
result.Data = channel
|
}
|
||||||
})
|
return channel, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlChannelStore) AnalyticsTypeCount(teamId string, channelType string) (int64, *model.AppError) {
|
func (s SqlChannelStore) AnalyticsTypeCount(teamId string, channelType string) (int64, *model.AppError) {
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ type ChannelStore interface {
|
|||||||
GetTeamChannels(teamId string) (*model.ChannelList, *model.AppError)
|
GetTeamChannels(teamId string) (*model.ChannelList, *model.AppError)
|
||||||
GetAll(teamId string) StoreChannel
|
GetAll(teamId string) StoreChannel
|
||||||
GetChannelsByIds(channelIds []string) ([]*model.Channel, *model.AppError)
|
GetChannelsByIds(channelIds []string) ([]*model.Channel, *model.AppError)
|
||||||
GetForPost(postId string) StoreChannel
|
GetForPost(postId string) (*model.Channel, *model.AppError)
|
||||||
SaveMember(member *model.ChannelMember) StoreChannel
|
SaveMember(member *model.ChannelMember) StoreChannel
|
||||||
UpdateMember(member *model.ChannelMember) StoreChannel
|
UpdateMember(member *model.ChannelMember) StoreChannel
|
||||||
GetMembers(channelId string, offset, limit int) StoreChannel
|
GetMembers(channelId string, offset, limit int) StoreChannel
|
||||||
|
|||||||
@@ -528,9 +528,9 @@ func testChannelStoreGetForPost(t *testing.T, ss store.Store) {
|
|||||||
})
|
})
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
if r1 := <-ss.Channel().GetForPost(p1.Id); r1.Err != nil {
|
if channel, chanErr := ss.Channel().GetForPost(p1.Id); chanErr != nil {
|
||||||
t.Fatal(r1.Err)
|
t.Fatal(chanErr)
|
||||||
} else if r1.Data.(*model.Channel).Id != o1.Id {
|
} else if channel.Id != o1.Id {
|
||||||
t.Fatal("incorrect channel returned")
|
t.Fatal("incorrect channel returned")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -566,19 +566,28 @@ func (_m *ChannelStore) GetDeletedByName(team_id string, name string) store.Stor
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetForPost provides a mock function with given fields: postId
|
// GetForPost provides a mock function with given fields: postId
|
||||||
func (_m *ChannelStore) GetForPost(postId string) store.StoreChannel {
|
func (_m *ChannelStore) GetForPost(postId string) (*model.Channel, *model.AppError) {
|
||||||
ret := _m.Called(postId)
|
ret := _m.Called(postId)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 *model.Channel
|
||||||
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string) *model.Channel); ok {
|
||||||
r0 = rf(postId)
|
r0 = rf(postId)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
r0 = ret.Get(0).(*model.Channel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
var r1 *model.AppError
|
||||||
|
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
|
||||||
|
r1 = rf(postId)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFromMaster provides a mock function with given fields: id
|
// GetFromMaster provides a mock function with given fields: id
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user