MM-15843 migrating post.GetSingle() to sync by default (#10992)
Этот коммит содержится в:
коммит произвёл
Hanzei
родитель
8ff58a07bd
Коммит
427effcd5c
@@ -27,6 +27,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/store"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
)
|
||||
|
||||
@@ -61,8 +62,15 @@ func (a *App) DoPostActionWithCookie(postId, actionId, userId, selectedOption st
|
||||
|
||||
// See if the post exists in the DB, if so ignore the cookie.
|
||||
// Start all queries here for parallel execution
|
||||
pchan := a.Srv.Store.Post().GetSingle(postId)
|
||||
pchan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
post, err := a.Srv.Store.Post().GetSingle(postId)
|
||||
pchan <- store.StoreResult{Data: post, Err: err}
|
||||
close(pchan)
|
||||
}()
|
||||
|
||||
cchan := a.Srv.Store.Channel().GetForPost(postId)
|
||||
|
||||
result := <-pchan
|
||||
if result.Err != nil {
|
||||
if cookie == nil {
|
||||
@@ -86,9 +94,7 @@ func (a *App) DoPostActionWithCookie(postId, actionId, userId, selectedOption st
|
||||
rootPostId = cookie.RootPostId
|
||||
upstreamURL = cookie.Integration.URL
|
||||
} else {
|
||||
// Get action metadata from the database
|
||||
post := result.Data.(*model.Post)
|
||||
|
||||
result = <-cchan
|
||||
if result.Err != nil {
|
||||
return "", result.Err
|
||||
|
||||
@@ -381,10 +381,8 @@ func TestPostActionProps(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
assert.True(t, len(clientTriggerId) == 26)
|
||||
|
||||
pchan := th.App.Srv.Store.Post().GetSingle(post.Id)
|
||||
result := <-pchan
|
||||
require.Nil(t, result.Err)
|
||||
newPost := result.Data.(*model.Post)
|
||||
newPost, err := th.App.Srv.Store.Post().GetSingle(post.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
assert.True(t, newPost.IsPinned)
|
||||
assert.False(t, newPost.HasReactions)
|
||||
|
||||
@@ -176,11 +176,9 @@ func TestHookMessageWillBePosted(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, "message", post.Message)
|
||||
if result := <-th.App.Srv.Store.Post().GetSingle(post.Id); result.Err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
assert.Equal(t, "message", result.Data.(*model.Post).Message)
|
||||
}
|
||||
retrievedPost, errSingle := th.App.Srv.Store.Post().GetSingle(post.Id)
|
||||
require.Nil(t, errSingle)
|
||||
assert.Equal(t, "message", retrievedPost.Message)
|
||||
})
|
||||
|
||||
t.Run("updated", func(t *testing.T) {
|
||||
@@ -223,10 +221,10 @@ func TestHookMessageWillBePosted(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, "message_fromplugin", post.Message)
|
||||
if result := <-th.App.Srv.Store.Post().GetSingle(post.Id); result.Err != nil {
|
||||
t.Fatal(err)
|
||||
if retrievedPost, errSingle := th.App.Srv.Store.Post().GetSingle(post.Id); err != nil {
|
||||
t.Fatal(errSingle)
|
||||
} else {
|
||||
assert.Equal(t, "message_fromplugin", result.Data.(*model.Post).Message)
|
||||
assert.Equal(t, "message_fromplugin", retrievedPost.Message)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
23
app/post.go
23
app/post.go
@@ -627,11 +627,7 @@ func (a *App) GetPostsSince(channelId string, time int64) (*model.PostList, *mod
|
||||
}
|
||||
|
||||
func (a *App) GetSinglePost(postId string) (*model.Post, *model.AppError) {
|
||||
result := <-a.Srv.Store.Post().GetSingle(postId)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
return result.Data.(*model.Post), nil
|
||||
return a.Srv.Store.Post().GetSingle(postId)
|
||||
}
|
||||
|
||||
func (a *App) GetPostThread(postId string) (*model.PostList, *model.AppError) {
|
||||
@@ -709,12 +705,11 @@ func (a *App) GetPostsAroundPost(postId, channelId string, offset, limit int, be
|
||||
}
|
||||
|
||||
func (a *App) DeletePost(postId, deleteByID string) (*model.Post, *model.AppError) {
|
||||
result := <-a.Srv.Store.Post().GetSingle(postId)
|
||||
if result.Err != nil {
|
||||
result.Err.StatusCode = http.StatusBadRequest
|
||||
return nil, result.Err
|
||||
post, err := a.Srv.Store.Post().GetSingle(postId)
|
||||
if err != nil {
|
||||
err.StatusCode = http.StatusBadRequest
|
||||
return nil, err
|
||||
}
|
||||
post := result.Data.(*model.Post)
|
||||
|
||||
channel, err := a.GetChannel(post.ChannelId)
|
||||
if err != nil {
|
||||
@@ -945,7 +940,13 @@ func (a *App) SearchPostsInTeamForUser(terms string, userId string, teamId strin
|
||||
}
|
||||
|
||||
func (a *App) GetFileInfosForPostWithMigration(postId string) ([]*model.FileInfo, *model.AppError) {
|
||||
pchan := a.Srv.Store.Post().GetSingle(postId)
|
||||
|
||||
pchan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
post, err := a.Srv.Store.Post().GetSingle(postId)
|
||||
pchan <- store.StoreResult{Data: post, Err: err}
|
||||
close(pchan)
|
||||
}()
|
||||
|
||||
infos, err := a.GetFileInfosForPost(postId, false)
|
||||
if err != nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user