[MM-15858] Migrate "Post.GetPostsCreatedAt" to Sync by default (#11021)
* Migrate "Post.GetPostsCreatedAt" to Sync by default * Fix variable misuse
Этот коммит содержится в:
коммит произвёл
Jesse Hallam
родитель
cc6c385d3e
Коммит
a57e042dab
@@ -1093,19 +1093,16 @@ func (s *SqlPostStore) AnalyticsPostCount(teamId string, mustHaveFile bool, must
|
||||
})
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) GetPostsCreatedAt(channelId string, time int64) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
query := `SELECT * FROM Posts WHERE CreateAt = :CreateAt AND ChannelId = :ChannelId`
|
||||
func (s *SqlPostStore) GetPostsCreatedAt(channelId string, time int64) ([]*model.Post, *model.AppError) {
|
||||
query := `SELECT * FROM Posts WHERE CreateAt = :CreateAt AND ChannelId = :ChannelId`
|
||||
|
||||
var posts []*model.Post
|
||||
_, err := s.GetReplica().Select(&posts, query, map[string]interface{}{"CreateAt": time, "ChannelId": channelId})
|
||||
var posts []*model.Post
|
||||
_, err := s.GetReplica().Select(&posts, query, map[string]interface{}{"CreateAt": time, "ChannelId": channelId})
|
||||
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlPostStore.GetPostsCreatedAt", "store.sql_post.get_posts_created_att.app_error", nil, "channelId="+channelId+err.Error(), http.StatusInternalServerError)
|
||||
} else {
|
||||
result.Data = posts
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlPostStore.GetPostsCreatedAt", "store.sql_post.get_posts_created_att.app_error", nil, "channelId="+channelId+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return posts, nil
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) GetPostsByIds(postIds []string) store.StoreChannel {
|
||||
|
||||
@@ -231,7 +231,7 @@ type PostStore interface {
|
||||
AnalyticsPostCount(teamId string, mustHaveFile bool, mustHaveHashtag bool) StoreChannel
|
||||
ClearCaches()
|
||||
InvalidateLastPostTimeCache(channelId string)
|
||||
GetPostsCreatedAt(channelId string, time int64) StoreChannel
|
||||
GetPostsCreatedAt(channelId string, time int64) ([]*model.Post, *model.AppError)
|
||||
Overwrite(post *model.Post) (*model.Post, *model.AppError)
|
||||
GetPostsByIds(postIds []string) StoreChannel
|
||||
GetPostsBatchForIndexing(startTime int64, endTime int64, limit int) StoreChannel
|
||||
|
||||
@@ -366,19 +366,28 @@ func (_m *PostStore) GetPostsByIds(postIds []string) store.StoreChannel {
|
||||
}
|
||||
|
||||
// GetPostsCreatedAt provides a mock function with given fields: channelId, time
|
||||
func (_m *PostStore) GetPostsCreatedAt(channelId string, time int64) store.StoreChannel {
|
||||
func (_m *PostStore) GetPostsCreatedAt(channelId string, time int64) ([]*model.Post, *model.AppError) {
|
||||
ret := _m.Called(channelId, time)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string, int64) store.StoreChannel); ok {
|
||||
var r0 []*model.Post
|
||||
if rf, ok := ret.Get(0).(func(string, int64) []*model.Post); ok {
|
||||
r0 = rf(channelId, time)
|
||||
} 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(string, int64) *model.AppError); ok {
|
||||
r1 = rf(channelId, time)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetPostsSince provides a mock function with given fields: channelId, time, allowFromCache
|
||||
|
||||
@@ -351,8 +351,8 @@ func testPostStoreDelete(t *testing.T, ss store.Store) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
r5 := <-ss.Post().GetPostsCreatedAt(o1.ChannelId, o1.CreateAt)
|
||||
post := r5.Data.([]*model.Post)[0]
|
||||
posts, _ := ss.Post().GetPostsCreatedAt(o1.ChannelId, o1.CreateAt)
|
||||
post := posts[0]
|
||||
actual := post.Props[model.POST_PROPS_DELETE_BY]
|
||||
if actual != deleteByID {
|
||||
t.Errorf("Expected (*Post).Props[model.POST_PROPS_DELETE_BY] to be %v but got %v.", deleteByID, actual)
|
||||
@@ -1759,7 +1759,7 @@ func testPostStoreGetPostsCreatedAt(t *testing.T, ss store.Store) {
|
||||
o3.CreateAt = createTime
|
||||
_ = (<-ss.Post().Save(o3)).Data.(*model.Post)
|
||||
|
||||
r1 := (<-ss.Post().GetPostsCreatedAt(o1.ChannelId, createTime)).Data.([]*model.Post)
|
||||
r1, _ := ss.Post().GetPostsCreatedAt(o1.ChannelId, createTime)
|
||||
assert.Equal(t, 2, len(r1))
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user