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
Этот коммит содержится в:
@@ -97,13 +97,7 @@ func (s *SqlPostStore) Save(post *model.Post) store.StoreChannel {
|
||||
return
|
||||
}
|
||||
|
||||
var maxPostSize int
|
||||
if result := <-s.GetMaxPostSize(); result.Err != nil {
|
||||
result.Err = model.NewAppError("SqlPostStore.Save", "store.sql_post.save.app_error", nil, "id="+post.Id+", "+result.Err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
} else {
|
||||
maxPostSize = result.Data.(int)
|
||||
}
|
||||
maxPostSize := s.GetMaxPostSize()
|
||||
|
||||
post.PreSave()
|
||||
if result.Err = post.IsValid(maxPostSize); result.Err != nil {
|
||||
@@ -146,13 +140,7 @@ func (s *SqlPostStore) Update(newPost *model.Post, oldPost *model.Post) store.St
|
||||
oldPost.Id = model.NewId()
|
||||
oldPost.PreCommit()
|
||||
|
||||
var maxPostSize int
|
||||
if result := <-s.GetMaxPostSize(); result.Err != nil {
|
||||
result.Err = model.NewAppError("SqlPostStore.Save", "store.sql_post.update.app_error", nil, "id="+newPost.Id+", "+result.Err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
} else {
|
||||
maxPostSize = result.Data.(int)
|
||||
}
|
||||
maxPostSize := s.GetMaxPostSize()
|
||||
|
||||
if result.Err = newPost.IsValid(maxPostSize); result.Err != nil {
|
||||
return
|
||||
@@ -176,28 +164,19 @@ func (s *SqlPostStore) Update(newPost *model.Post, oldPost *model.Post) store.St
|
||||
})
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) Overwrite(post *model.Post) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
post.UpdateAt = model.GetMillis()
|
||||
func (s *SqlPostStore) Overwrite(post *model.Post) (*model.Post, *model.AppError) {
|
||||
post.UpdateAt = model.GetMillis()
|
||||
|
||||
var maxPostSize int
|
||||
if result := <-s.GetMaxPostSize(); result.Err != nil {
|
||||
result.Err = model.NewAppError("SqlPostStore.Save", "store.sql_post.overwrite.app_error", nil, "id="+post.Id+", "+result.Err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
} else {
|
||||
maxPostSize = result.Data.(int)
|
||||
}
|
||||
maxPostSize := s.GetMaxPostSize()
|
||||
if appErr := post.IsValid(maxPostSize); appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
if result.Err = post.IsValid(maxPostSize); result.Err != nil {
|
||||
return
|
||||
}
|
||||
if _, err := s.GetMaster().Update(post); err != nil {
|
||||
return nil, model.NewAppError("SqlPostStore.Overwrite", "store.sql_post.overwrite.app_error", nil, "id="+post.Id+", "+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if _, err := s.GetMaster().Update(post); err != nil {
|
||||
result.Err = model.NewAppError("SqlPostStore.Overwrite", "store.sql_post.overwrite.app_error", nil, "id="+post.Id+", "+err.Error(), http.StatusInternalServerError)
|
||||
} else {
|
||||
result.Data = post
|
||||
}
|
||||
})
|
||||
return post, nil
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) GetFlaggedPosts(userId string, offset int, limit int) store.StoreChannel {
|
||||
@@ -1296,13 +1275,11 @@ func (s *SqlPostStore) determineMaxPostSize() int {
|
||||
}
|
||||
|
||||
// GetMaxPostSize returns the maximum number of runes that may be stored in a post.
|
||||
func (s *SqlPostStore) GetMaxPostSize() store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
s.maxPostSizeOnce.Do(func() {
|
||||
s.maxPostSizeCached = s.determineMaxPostSize()
|
||||
})
|
||||
result.Data = s.maxPostSizeCached
|
||||
func (s *SqlPostStore) GetMaxPostSize() int {
|
||||
s.maxPostSizeOnce.Do(func() {
|
||||
s.maxPostSizeCached = s.determineMaxPostSize()
|
||||
})
|
||||
return s.maxPostSizeCached
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) GetParentsForExportAfter(limit int, afterId string) store.StoreChannel {
|
||||
|
||||
@@ -232,12 +232,12 @@ type PostStore interface {
|
||||
ClearCaches()
|
||||
InvalidateLastPostTimeCache(channelId string)
|
||||
GetPostsCreatedAt(channelId string, time int64) StoreChannel
|
||||
Overwrite(post *model.Post) StoreChannel
|
||||
Overwrite(post *model.Post) (*model.Post, *model.AppError)
|
||||
GetPostsByIds(postIds []string) StoreChannel
|
||||
GetPostsBatchForIndexing(startTime int64, endTime int64, limit int) StoreChannel
|
||||
PermanentDeleteBatch(endTime int64, limit int64) StoreChannel
|
||||
GetOldest() StoreChannel
|
||||
GetMaxPostSize() StoreChannel
|
||||
GetMaxPostSize() int
|
||||
GetParentsForExportAfter(limit int, afterId string) StoreChannel
|
||||
GetRepliesForExport(parentId string) StoreChannel
|
||||
GetDirectPostParentsForExportAfter(limit int, afterId string) StoreChannel
|
||||
|
||||
@@ -179,16 +179,14 @@ func (_m *PostStore) GetFlaggedPostsForTeam(userId string, teamId string, offset
|
||||
}
|
||||
|
||||
// GetMaxPostSize provides a mock function with given fields:
|
||||
func (_m *PostStore) GetMaxPostSize() store.StoreChannel {
|
||||
func (_m *PostStore) GetMaxPostSize() int {
|
||||
ret := _m.Called()
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func() store.StoreChannel); ok {
|
||||
var r0 int
|
||||
if rf, ok := ret.Get(0).(func() int); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
}
|
||||
r0 = ret.Get(0).(int)
|
||||
}
|
||||
|
||||
return r0
|
||||
@@ -376,19 +374,28 @@ func (_m *PostStore) InvalidateLastPostTimeCache(channelId string) {
|
||||
}
|
||||
|
||||
// Overwrite provides a mock function with given fields: post
|
||||
func (_m *PostStore) Overwrite(post *model.Post) store.StoreChannel {
|
||||
func (_m *PostStore) Overwrite(post *model.Post) (*model.Post, *model.AppError) {
|
||||
ret := _m.Called(post)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(*model.Post) store.StoreChannel); ok {
|
||||
var r0 *model.Post
|
||||
if rf, ok := ret.Get(0).(func(*model.Post) *model.Post); ok {
|
||||
r0 = rf(post)
|
||||
} else {
|
||||
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(*model.Post) *model.AppError); ok {
|
||||
r1 = rf(post)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// PermanentDeleteBatch provides a mock function with given fields: endTime, limit
|
||||
|
||||
@@ -1638,8 +1638,8 @@ func testPostStoreOverwrite(t *testing.T, ss store.Store) {
|
||||
o1a := &model.Post{}
|
||||
*o1a = *ro1
|
||||
o1a.Message = ro1.Message + "BBBBBBBBBB"
|
||||
if result := <-ss.Post().Overwrite(o1a); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
if _, err := ss.Post().Overwrite(o1a); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ro1a := (<-ss.Post().Get(o1.Id)).Data.(*model.PostList).Posts[o1.Id]
|
||||
@@ -1651,8 +1651,8 @@ func testPostStoreOverwrite(t *testing.T, ss store.Store) {
|
||||
o2a := &model.Post{}
|
||||
*o2a = *ro2
|
||||
o2a.Message = ro2.Message + "DDDDDDD"
|
||||
if result := <-ss.Post().Overwrite(o2a); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
if _, err := ss.Post().Overwrite(o2a); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ro2a := (<-ss.Post().Get(o1.Id)).Data.(*model.PostList).Posts[o2.Id]
|
||||
@@ -1664,8 +1664,8 @@ func testPostStoreOverwrite(t *testing.T, ss store.Store) {
|
||||
o3a := &model.Post{}
|
||||
*o3a = *ro3
|
||||
o3a.Message = ro3.Message + "WWWWWWW"
|
||||
if result := <-ss.Post().Overwrite(o3a); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
if _, err := ss.Post().Overwrite(o3a); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ro3a := (<-ss.Post().Get(o3.Id)).Data.(*model.PostList).Posts[o3.Id]
|
||||
@@ -1687,8 +1687,8 @@ func testPostStoreOverwrite(t *testing.T, ss store.Store) {
|
||||
*o4a = *ro4
|
||||
o4a.Filenames = []string{}
|
||||
o4a.FileIds = []string{model.NewId()}
|
||||
if result := <-ss.Post().Overwrite(o4a); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
if _, err := ss.Post().Overwrite(o4a); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if ro4a := store.Must(ss.Post().Get(o4.Id)).(*model.PostList).Posts[o4.Id]; len(ro4a.Filenames) != 0 {
|
||||
@@ -1872,8 +1872,8 @@ func testPostStoreGetOldest(t *testing.T, ss store.Store) {
|
||||
}
|
||||
|
||||
func testGetMaxPostSize(t *testing.T, ss store.Store) {
|
||||
assert.Equal(t, model.POST_MESSAGE_MAX_RUNES_V2, (<-ss.Post().GetMaxPostSize()).Data.(int))
|
||||
assert.Equal(t, model.POST_MESSAGE_MAX_RUNES_V2, (<-ss.Post().GetMaxPostSize()).Data.(int))
|
||||
assert.Equal(t, model.POST_MESSAGE_MAX_RUNES_V2, ss.Post().GetMaxPostSize())
|
||||
assert.Equal(t, model.POST_MESSAGE_MAX_RUNES_V2, ss.Post().GetMaxPostSize())
|
||||
}
|
||||
|
||||
func testPostStoreGetParentsForExportAfter(t *testing.T, ss store.Store) {
|
||||
|
||||
Ссылка в новой задаче
Block a user