MM-15198 Migrate Channel.Get/GetFromMaster to Sync by default (#10667)
* MM-15198 Migrate Channel.Get/GetFromMaster to Sync by default * MM-15198 - Update store/storetest/post_store.go fix error handling in post_store.go test case Co-Authored-By: andresoro <ao15@my.fsu.edu>
Этот коммит содержится в:
коммит произвёл
Miguel de la Cruz
родитель
370e9eedb1
Коммит
928ecba2d4
@@ -1109,16 +1109,16 @@ func (a *App) PostUpdateChannelDisplayNameMessage(userId string, channel *model.
|
||||
}
|
||||
|
||||
func (a *App) GetChannel(channelId string) (*model.Channel, *model.AppError) {
|
||||
result := <-a.Srv.Store.Channel().Get(channelId, true)
|
||||
if result.Err != nil {
|
||||
if result.Err.Id == "store.sql_channel.get.existing.app_error" {
|
||||
result.Err.StatusCode = http.StatusNotFound
|
||||
return nil, result.Err
|
||||
channel, errCh := a.Srv.Store.Channel().Get(channelId, true)
|
||||
if errCh != nil {
|
||||
if errCh.Id == "store.sql_channel.get.existing.app_error" {
|
||||
errCh.StatusCode = http.StatusNotFound
|
||||
return nil, errCh
|
||||
}
|
||||
result.Err.StatusCode = http.StatusBadRequest
|
||||
return nil, result.Err
|
||||
errCh.StatusCode = http.StatusBadRequest
|
||||
return nil, errCh
|
||||
}
|
||||
return result.Data.(*model.Channel), nil
|
||||
return channel, nil
|
||||
}
|
||||
|
||||
func (a *App) GetChannelByName(channelName, teamId string, includeDeleted bool) (*model.Channel, *model.AppError) {
|
||||
@@ -1424,7 +1424,13 @@ func (a *App) postJoinTeamMessage(user *model.User, channel *model.Channel) *mod
|
||||
}
|
||||
|
||||
func (a *App) LeaveChannel(channelId string, userId string) *model.AppError {
|
||||
sc := a.Srv.Store.Channel().Get(channelId, true)
|
||||
sc := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
channel, err := a.Srv.Store.Channel().Get(channelId, true)
|
||||
sc <- store.StoreResult{Data: channel, Err: err}
|
||||
close(sc)
|
||||
}()
|
||||
|
||||
uc := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
user, err := a.Srv.Store.User().Get(userId)
|
||||
@@ -1763,12 +1769,11 @@ func (a *App) MarkChannelsAsViewed(channelIds []string, userId string, currentSe
|
||||
channelsToClearPushNotifications := []string{}
|
||||
if *a.Config().EmailSettings.SendPushNotifications {
|
||||
for _, channelId := range channelIds {
|
||||
chanResult := <-a.Srv.Store.Channel().Get(channelId, true)
|
||||
if chanResult.Err != nil {
|
||||
mlog.Warn(fmt.Sprintf("Failed to get channel %v", chanResult.Err))
|
||||
channel, errCh := a.Srv.Store.Channel().Get(channelId, true)
|
||||
if errCh != nil {
|
||||
mlog.Warn(fmt.Sprintf("Failed to get channel %v", errCh))
|
||||
continue
|
||||
}
|
||||
channel := chanResult.Data.(*model.Channel)
|
||||
|
||||
member, err := a.Srv.Store.Channel().GetMember(channelId, userId)
|
||||
if err != nil {
|
||||
|
||||
@@ -218,7 +218,12 @@ func (a *App) tryExecuteCustomCommand(args *model.CommandArgs, trigger string, m
|
||||
return nil, nil, model.NewAppError("ExecuteCommand", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
chanChan := a.Srv.Store.Channel().Get(args.ChannelId, true)
|
||||
chanChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
channel, err := a.Srv.Store.Channel().Get(args.ChannelId, true)
|
||||
chanChan <- store.StoreResult{Data: channel, Err: err}
|
||||
close(chanChan)
|
||||
}()
|
||||
teamChan := a.Srv.Store.Team().Get(args.TeamId)
|
||||
userChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
|
||||
@@ -216,12 +216,11 @@ func (s *Server) sendBatchedEmailNotification(userId string, notifications []*ba
|
||||
continue
|
||||
}
|
||||
|
||||
result := <-s.Store.Channel().Get(notification.post.ChannelId, true)
|
||||
if result.Err != nil {
|
||||
channel, errCh := s.Store.Channel().Get(notification.post.ChannelId, true)
|
||||
if errCh != nil {
|
||||
mlog.Warn("Unable to find channel of post for batched email notification")
|
||||
continue
|
||||
}
|
||||
channel := result.Data.(*model.Channel)
|
||||
|
||||
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
|
||||
if license := s.License(); license != nil && *license.Features.EmailNotificationContents {
|
||||
|
||||
12
app/file.go
12
app/file.go
@@ -225,21 +225,17 @@ func (a *App) MigrateFilenamesToFileInfos(post *model.Post) []*model.FileInfo {
|
||||
return []*model.FileInfo{}
|
||||
}
|
||||
|
||||
cchan := a.Srv.Store.Channel().Get(post.ChannelId, true)
|
||||
|
||||
channel, errCh := a.Srv.Store.Channel().Get(post.ChannelId, true)
|
||||
// There's a weird bug that rarely happens where a post ends up with duplicate Filenames so remove those
|
||||
filenames := utils.RemoveDuplicatesFromStringArray(post.Filenames)
|
||||
|
||||
result := <-cchan
|
||||
if result.Err != nil {
|
||||
if errCh != nil {
|
||||
mlog.Error(
|
||||
fmt.Sprintf("Unable to get channel when migrating post to use FileInfos, err=%v", result.Err),
|
||||
fmt.Sprintf("Unable to get channel when migrating post to use FileInfos, err=%v", errCh),
|
||||
mlog.String("post_id", post.Id),
|
||||
mlog.String("channel_id", post.ChannelId),
|
||||
)
|
||||
return []*model.FileInfo{}
|
||||
}
|
||||
channel := result.Data.(*model.Channel)
|
||||
|
||||
// Find the team that was used to make this post since its part of the file path that isn't saved in the Filename
|
||||
var teamId string
|
||||
@@ -272,7 +268,7 @@ func (a *App) MigrateFilenamesToFileInfos(post *model.Post) []*model.FileInfo {
|
||||
fileMigrationLock.Lock()
|
||||
defer fileMigrationLock.Unlock()
|
||||
|
||||
result = <-a.Srv.Store.Post().Get(post.Id)
|
||||
result := <-a.Srv.Store.Post().Get(post.Id)
|
||||
if result.Err != nil {
|
||||
mlog.Error(fmt.Sprintf("Unable to get post when migrating post to use FileInfos, err=%v", result.Err), mlog.String("post_id", post.Id))
|
||||
return []*model.FileInfo{}
|
||||
|
||||
14
app/post.go
14
app/post.go
@@ -24,12 +24,11 @@ const (
|
||||
|
||||
func (a *App) CreatePostAsUser(post *model.Post, currentSessionId string) (*model.Post, *model.AppError) {
|
||||
// Check that channel has not been deleted
|
||||
result := <-a.Srv.Store.Channel().Get(post.ChannelId, true)
|
||||
if result.Err != nil {
|
||||
err := model.NewAppError("CreatePostAsUser", "api.context.invalid_param.app_error", map[string]interface{}{"Name": "post.channel_id"}, result.Err.Error(), http.StatusBadRequest)
|
||||
channel, errCh := a.Srv.Store.Channel().Get(post.ChannelId, true)
|
||||
if errCh != nil {
|
||||
err := model.NewAppError("CreatePostAsUser", "api.context.invalid_param.app_error", map[string]interface{}{"Name": "post.channel_id"}, errCh.Error(), http.StatusBadRequest)
|
||||
return nil, err
|
||||
}
|
||||
channel := result.Data.(*model.Channel)
|
||||
|
||||
if strings.HasPrefix(post.Type, model.POST_SYSTEM_MESSAGE_PREFIX) {
|
||||
err := model.NewAppError("CreatePostAsUser", "api.context.invalid_param.app_error", map[string]interface{}{"Name": "post.type"}, "", http.StatusBadRequest)
|
||||
@@ -82,11 +81,10 @@ func (a *App) CreatePostAsUser(post *model.Post, currentSessionId string) (*mode
|
||||
}
|
||||
|
||||
func (a *App) CreatePostMissingChannel(post *model.Post, triggerWebhooks bool) (*model.Post, *model.AppError) {
|
||||
result := <-a.Srv.Store.Channel().Get(post.ChannelId, true)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
channel, err := a.Srv.Store.Channel().Get(post.ChannelId, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
channel := result.Data.(*model.Channel)
|
||||
|
||||
return a.CreatePost(post, channel, triggerWebhooks)
|
||||
}
|
||||
|
||||
@@ -401,13 +401,9 @@ func (a *App) CreateOutgoingWebhook(hook *model.OutgoingWebhook) (*model.Outgoin
|
||||
}
|
||||
|
||||
if len(hook.ChannelId) != 0 {
|
||||
cchan := a.Srv.Store.Channel().Get(hook.ChannelId, true)
|
||||
|
||||
var channel *model.Channel
|
||||
if result := <-cchan; result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
channel = result.Data.(*model.Channel)
|
||||
channel, errCh := a.Srv.Store.Channel().Get(hook.ChannelId, true)
|
||||
if errCh != nil {
|
||||
return nil, errCh
|
||||
}
|
||||
|
||||
if channel.Type != model.CHANNEL_OPEN {
|
||||
@@ -641,7 +637,11 @@ func (a *App) HandleIncomingWebhook(hookId string, req *model.IncomingWebhookReq
|
||||
cchan = a.Srv.Store.Channel().GetByName(hook.TeamId, channelName, true)
|
||||
}
|
||||
} else {
|
||||
cchan = a.Srv.Store.Channel().Get(hook.ChannelId, true)
|
||||
var err *model.AppError
|
||||
channel, err = a.Srv.Store.Channel().Get(hook.ChannelId, true)
|
||||
if err != nil {
|
||||
return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.channel.app_error", nil, "err="+err.Message, err.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
if channel == nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user