MM-15843 migrating post.GetSingle() to sync by default (#10992)
Этот коммит содержится в:
коммит произвёл
Hanzei
родитель
8ff58a07bd
Коммит
427effcd5c
@@ -27,6 +27,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
|
"github.com/mattermost/mattermost-server/store"
|
||||||
"github.com/mattermost/mattermost-server/utils"
|
"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.
|
// See if the post exists in the DB, if so ignore the cookie.
|
||||||
// Start all queries here for parallel execution
|
// 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)
|
cchan := a.Srv.Store.Channel().GetForPost(postId)
|
||||||
|
|
||||||
result := <-pchan
|
result := <-pchan
|
||||||
if result.Err != nil {
|
if result.Err != nil {
|
||||||
if cookie == nil {
|
if cookie == nil {
|
||||||
@@ -86,9 +94,7 @@ func (a *App) DoPostActionWithCookie(postId, actionId, userId, selectedOption st
|
|||||||
rootPostId = cookie.RootPostId
|
rootPostId = cookie.RootPostId
|
||||||
upstreamURL = cookie.Integration.URL
|
upstreamURL = cookie.Integration.URL
|
||||||
} else {
|
} else {
|
||||||
// Get action metadata from the database
|
|
||||||
post := result.Data.(*model.Post)
|
post := result.Data.(*model.Post)
|
||||||
|
|
||||||
result = <-cchan
|
result = <-cchan
|
||||||
if result.Err != nil {
|
if result.Err != nil {
|
||||||
return "", result.Err
|
return "", result.Err
|
||||||
|
|||||||
@@ -381,10 +381,8 @@ func TestPostActionProps(t *testing.T) {
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
assert.True(t, len(clientTriggerId) == 26)
|
assert.True(t, len(clientTriggerId) == 26)
|
||||||
|
|
||||||
pchan := th.App.Srv.Store.Post().GetSingle(post.Id)
|
newPost, err := th.App.Srv.Store.Post().GetSingle(post.Id)
|
||||||
result := <-pchan
|
require.Nil(t, err)
|
||||||
require.Nil(t, result.Err)
|
|
||||||
newPost := result.Data.(*model.Post)
|
|
||||||
|
|
||||||
assert.True(t, newPost.IsPinned)
|
assert.True(t, newPost.IsPinned)
|
||||||
assert.False(t, newPost.HasReactions)
|
assert.False(t, newPost.HasReactions)
|
||||||
|
|||||||
@@ -176,11 +176,9 @@ func TestHookMessageWillBePosted(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
assert.Equal(t, "message", post.Message)
|
assert.Equal(t, "message", post.Message)
|
||||||
if result := <-th.App.Srv.Store.Post().GetSingle(post.Id); result.Err != nil {
|
retrievedPost, errSingle := th.App.Srv.Store.Post().GetSingle(post.Id)
|
||||||
t.Fatal(err)
|
require.Nil(t, errSingle)
|
||||||
} else {
|
assert.Equal(t, "message", retrievedPost.Message)
|
||||||
assert.Equal(t, "message", result.Data.(*model.Post).Message)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("updated", func(t *testing.T) {
|
t.Run("updated", func(t *testing.T) {
|
||||||
@@ -223,10 +221,10 @@ func TestHookMessageWillBePosted(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
assert.Equal(t, "message_fromplugin", post.Message)
|
assert.Equal(t, "message_fromplugin", post.Message)
|
||||||
if result := <-th.App.Srv.Store.Post().GetSingle(post.Id); result.Err != nil {
|
if retrievedPost, errSingle := th.App.Srv.Store.Post().GetSingle(post.Id); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(errSingle)
|
||||||
} else {
|
} 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) {
|
func (a *App) GetSinglePost(postId string) (*model.Post, *model.AppError) {
|
||||||
result := <-a.Srv.Store.Post().GetSingle(postId)
|
return a.Srv.Store.Post().GetSingle(postId)
|
||||||
if result.Err != nil {
|
|
||||||
return nil, result.Err
|
|
||||||
}
|
|
||||||
return result.Data.(*model.Post), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetPostThread(postId string) (*model.PostList, *model.AppError) {
|
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) {
|
func (a *App) DeletePost(postId, deleteByID string) (*model.Post, *model.AppError) {
|
||||||
result := <-a.Srv.Store.Post().GetSingle(postId)
|
post, err := a.Srv.Store.Post().GetSingle(postId)
|
||||||
if result.Err != nil {
|
if err != nil {
|
||||||
result.Err.StatusCode = http.StatusBadRequest
|
err.StatusCode = http.StatusBadRequest
|
||||||
return nil, result.Err
|
return nil, err
|
||||||
}
|
}
|
||||||
post := result.Data.(*model.Post)
|
|
||||||
|
|
||||||
channel, err := a.GetChannel(post.ChannelId)
|
channel, err := a.GetChannel(post.ChannelId)
|
||||||
if err != nil {
|
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) {
|
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)
|
infos, err := a.GetFileInfosForPost(postId, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -304,16 +304,13 @@ func (s *SqlPostStore) Get(id string) (*model.PostList, *model.AppError) {
|
|||||||
return pl, nil
|
return pl, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlPostStore) GetSingle(id string) store.StoreChannel {
|
func (s *SqlPostStore) GetSingle(id string) (*model.Post, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
|
||||||
var post model.Post
|
var post model.Post
|
||||||
err := s.GetReplica().SelectOne(&post, "SELECT * FROM Posts WHERE Id = :Id AND DeleteAt = 0", map[string]interface{}{"Id": id})
|
err := s.GetReplica().SelectOne(&post, "SELECT * FROM Posts WHERE Id = :Id AND DeleteAt = 0", map[string]interface{}{"Id": id})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlPostStore.GetSingle", "store.sql_post.get.app_error", nil, "id="+id+err.Error(), http.StatusNotFound)
|
return nil, model.NewAppError("SqlPostStore.GetSingle", "store.sql_post.get.app_error", nil, "id="+id+err.Error(), http.StatusNotFound)
|
||||||
}
|
}
|
||||||
|
return &post, nil
|
||||||
result.Data = &post
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type etagPosts struct {
|
type etagPosts struct {
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ type PostStore interface {
|
|||||||
Save(post *model.Post) StoreChannel
|
Save(post *model.Post) StoreChannel
|
||||||
Update(newPost *model.Post, oldPost *model.Post) (*model.Post, *model.AppError)
|
Update(newPost *model.Post, oldPost *model.Post) (*model.Post, *model.AppError)
|
||||||
Get(id string) (*model.PostList, *model.AppError)
|
Get(id string) (*model.PostList, *model.AppError)
|
||||||
GetSingle(id string) StoreChannel
|
GetSingle(id string) (*model.Post, *model.AppError)
|
||||||
Delete(postId string, time int64, deleteByID string) *model.AppError
|
Delete(postId string, time int64, deleteByID string) *model.AppError
|
||||||
PermanentDeleteByUser(userId string) StoreChannel
|
PermanentDeleteByUser(userId string) StoreChannel
|
||||||
PermanentDeleteByChannel(channelId string) *model.AppError
|
PermanentDeleteByChannel(channelId string) *model.AppError
|
||||||
|
|||||||
@@ -380,19 +380,28 @@ func (_m *PostStore) GetRepliesForExport(parentId string) store.StoreChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetSingle provides a mock function with given fields: id
|
// GetSingle provides a mock function with given fields: id
|
||||||
func (_m *PostStore) GetSingle(id string) store.StoreChannel {
|
func (_m *PostStore) GetSingle(id string) (*model.Post, *model.AppError) {
|
||||||
ret := _m.Called(id)
|
ret := _m.Called(id)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 *model.Post
|
||||||
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string) *model.Post); ok {
|
||||||
r0 = rf(id)
|
r0 = rf(id)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
r0 = ret.Get(0).(*model.Post)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
var r1 *model.AppError
|
||||||
|
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
|
||||||
|
r1 = rf(id)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// InvalidateLastPostTimeCache provides a mock function with given fields: channelId
|
// InvalidateLastPostTimeCache provides a mock function with given fields: channelId
|
||||||
|
|||||||
@@ -153,15 +153,15 @@ func testPostStoreGetSingle(t *testing.T, ss store.Store) {
|
|||||||
|
|
||||||
o1 = (<-ss.Post().Save(o1)).Data.(*model.Post)
|
o1 = (<-ss.Post().Save(o1)).Data.(*model.Post)
|
||||||
|
|
||||||
if r1 := <-ss.Post().GetSingle(o1.Id); r1.Err != nil {
|
if post, err := ss.Post().GetSingle(o1.Id); err != nil {
|
||||||
t.Fatal(r1.Err)
|
t.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
if r1.Data.(*model.Post).CreateAt != o1.CreateAt {
|
if post.CreateAt != o1.CreateAt {
|
||||||
t.Fatal("invalid returned post")
|
t.Fatal("invalid returned post")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := (<-ss.Post().GetSingle("123")).Err; err == nil {
|
if _, err := ss.Post().GetSingle("123"); err == nil {
|
||||||
t.Fatal("Missing id should have failed")
|
t.Fatal("Missing id should have failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user