mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Migrate Overwrite and GetMaxPostSize() in PostStore to sync by default (#10829)
* Migrate Overwrite and GetMaxPostSize() in PostStore to sync by default * GH-10762: fix return type for mock func * GH-10762: fix tests for MaxPostSize() mocks * fix imports
This commit is contained in:
@@ -898,8 +898,8 @@ func (a *App) ImportReply(data *ReplyImportData, post *model.Post, teamId string
|
||||
return result.Err
|
||||
}
|
||||
} else {
|
||||
if result := <-a.Srv.Store.Post().Overwrite(reply); result.Err != nil {
|
||||
return result.Err
|
||||
if _, err := a.Srv.Store.Post().Overwrite(reply); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1000,8 +1000,8 @@ func (a *App) ImportPost(data *PostImportData, dryRun bool) *model.AppError {
|
||||
return result.Err
|
||||
}
|
||||
} else {
|
||||
if result := <-a.Srv.Store.Post().Overwrite(post); result.Err != nil {
|
||||
return result.Err
|
||||
if _, err := a.Srv.Store.Post().Overwrite(post); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1224,8 +1224,8 @@ func (a *App) ImportDirectPost(data *DirectPostImportData, dryRun bool) *model.A
|
||||
return result.Err
|
||||
}
|
||||
} else {
|
||||
if result := <-a.Srv.Store.Post().Overwrite(post); result.Err != nil {
|
||||
return result.Err
|
||||
if _, err := a.Srv.Store.Post().Overwrite(post); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
13
app/post.go
13
app/post.go
@@ -315,9 +315,8 @@ func (a *App) attachFilesToPost(post *model.Post) *model.AppError {
|
||||
// We couldn't attach all files to the post, so ensure that post.FileIds reflects what was actually attached
|
||||
post.FileIds = attachedIds
|
||||
|
||||
result := <-a.Srv.Store.Post().Overwrite(post)
|
||||
if result.Err != nil {
|
||||
return result.Err
|
||||
if _, err := a.Srv.Store.Post().Overwrite(post); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1027,10 +1026,10 @@ func (a *App) ImageProxyRemover() (f func(string) string) {
|
||||
}
|
||||
|
||||
func (a *App) MaxPostSize() int {
|
||||
result := <-a.Srv.Store.Post().GetMaxPostSize()
|
||||
if result.Err != nil {
|
||||
mlog.Error(fmt.Sprint(result.Err))
|
||||
maxPostSize := a.Srv.Store.Post().GetMaxPostSize()
|
||||
if maxPostSize == 0 {
|
||||
return model.POST_MESSAGE_MAX_RUNES_V1
|
||||
}
|
||||
return result.Data.(int)
|
||||
|
||||
return maxPostSize
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/store"
|
||||
"github.com/mattermost/mattermost-server/store/storetest"
|
||||
)
|
||||
|
||||
@@ -565,25 +564,21 @@ func TestMaxPostSize(t *testing.T) {
|
||||
Description string
|
||||
StoreMaxPostSize int
|
||||
ExpectedMaxPostSize int
|
||||
ExpectedError *model.AppError
|
||||
}{
|
||||
{
|
||||
"error fetching max post size",
|
||||
"Max post size less than model.model.POST_MESSAGE_MAX_RUNES_V1 ",
|
||||
0,
|
||||
model.POST_MESSAGE_MAX_RUNES_V1,
|
||||
model.NewAppError("TestMaxPostSize", "this is an error", nil, "", http.StatusBadRequest),
|
||||
},
|
||||
{
|
||||
"4000 rune limit",
|
||||
4000,
|
||||
4000,
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"16383 rune limit",
|
||||
16383,
|
||||
16383,
|
||||
nil,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -595,12 +590,7 @@ func TestMaxPostSize(t *testing.T) {
|
||||
mockStore := &storetest.Store{}
|
||||
defer mockStore.AssertExpectations(t)
|
||||
|
||||
mockStore.PostStore.On("GetMaxPostSize").Return(
|
||||
storetest.NewStoreChannel(store.StoreResult{
|
||||
Data: testCase.StoreMaxPostSize,
|
||||
Err: testCase.ExpectedError,
|
||||
}),
|
||||
)
|
||||
mockStore.PostStore.On("GetMaxPostSize").Return(testCase.StoreMaxPostSize)
|
||||
|
||||
app := App{
|
||||
Srv: &Server{
|
||||
|
||||
Reference in New Issue
Block a user