Migrate "Post.GetPostsSince" to Sync by default #10976 (#11129)

* Migrate "Post.GetPostsSince" to Sync by default #10976

* Update GetPostsSince to Sync by default #10976

* Update GetPostsSince to Sync by default #10976

* Update GetPostsSince to Sync by default #10976
Этот коммит содержится в:
Taufiq Rahman
2019-06-14 19:22:47 +06:00
коммит произвёл Harrison Healey
родитель 1f02b0ce72
Коммит e101e1c020
5 изменённых файлов: 64 добавлений и 67 удалений

Просмотреть файл

@@ -615,11 +615,7 @@ func (a *App) GetPostsEtag(channelId string) string {
} }
func (a *App) GetPostsSince(channelId string, time int64) (*model.PostList, *model.AppError) { func (a *App) GetPostsSince(channelId string, time int64) (*model.PostList, *model.AppError) {
result := <-a.Srv.Store.Post().GetPostsSince(channelId, time, true) return a.Srv.Store.Post().GetPostsSince(channelId, time, true)
if result.Err != nil {
return nil, result.Err
}
return result.Data.(*model.PostList), nil
} }
func (a *App) GetSinglePost(postId string) (*model.Post, *model.AppError) { func (a *App) GetSinglePost(postId string) (*model.Post, *model.AppError) {

Просмотреть файл

@@ -501,8 +501,7 @@ func (s *SqlPostStore) GetPosts(channelId string, offset int, limit int, allowFr
return list, err return list, err
} }
func (s *SqlPostStore) GetPostsSince(channelId string, time int64, allowFromCache bool) store.StoreChannel { func (s *SqlPostStore) GetPostsSince(channelId string, time int64, allowFromCache bool) (*model.PostList, *model.AppError) {
return store.Do(func(result *store.StoreResult) {
if allowFromCache { if allowFromCache {
// If the last post in the channel's time is less than or equal to the time we are getting posts since, // If the last post in the channel's time is less than or equal to the time we are getting posts since,
// we can safely return no posts. // we can safely return no posts.
@@ -511,18 +510,13 @@ func (s *SqlPostStore) GetPostsSince(channelId string, time int64, allowFromCach
s.metrics.IncrementMemCacheHitCounter("Last Post Time") s.metrics.IncrementMemCacheHitCounter("Last Post Time")
} }
list := model.NewPostList() list := model.NewPostList()
result.Data = list return list, nil
return }
} else { }
if s.metrics != nil { if s.metrics != nil {
s.metrics.IncrementMemCacheMissCounter("Last Post Time") s.metrics.IncrementMemCacheMissCounter("Last Post Time")
} }
}
} else {
if s.metrics != nil {
s.metrics.IncrementMemCacheMissCounter("Last Post Time")
}
}
var posts []*model.Post var posts []*model.Post
_, err := s.GetReplica().Select(&posts, _, err := s.GetReplica().Select(&posts,
@@ -554,8 +548,8 @@ func (s *SqlPostStore) GetPostsSince(channelId string, time int64, allowFromCach
map[string]interface{}{"ChannelId": channelId, "Time": time}) map[string]interface{}{"ChannelId": channelId, "Time": time})
if err != nil { if err != nil {
result.Err = model.NewAppError("SqlPostStore.GetPostsSince", "store.sql_post.get_posts_since.app_error", nil, "channelId="+channelId+err.Error(), http.StatusInternalServerError) return nil, model.NewAppError("SqlPostStore.GetPostsSince", "store.sql_post.get_posts_since.app_error", nil, "channelId="+channelId+err.Error(), http.StatusInternalServerError)
} else { }
list := model.NewPostList() list := model.NewPostList()
@@ -573,9 +567,7 @@ func (s *SqlPostStore) GetPostsSince(channelId string, time int64, allowFromCach
s.lastPostTimeCache.AddWithExpiresInSecs(channelId, latestUpdate, LAST_POST_TIME_CACHE_SEC) s.lastPostTimeCache.AddWithExpiresInSecs(channelId, latestUpdate, LAST_POST_TIME_CACHE_SEC)
result.Data = list return list, nil
}
})
} }
func (s *SqlPostStore) GetPostsBefore(channelId string, postId string, limit int, offset int) (*model.PostList, *model.AppError) { func (s *SqlPostStore) GetPostsBefore(channelId string, postId string, limit int, offset int) (*model.PostList, *model.AppError) {

Просмотреть файл

@@ -223,7 +223,7 @@ type PostStore interface {
GetFlaggedPostsForChannel(userId, channelId string, offset int, limit int) (*model.PostList, *model.AppError) GetFlaggedPostsForChannel(userId, channelId string, offset int, limit int) (*model.PostList, *model.AppError)
GetPostsBefore(channelId string, postId string, numPosts int, offset int) (*model.PostList, *model.AppError) GetPostsBefore(channelId string, postId string, numPosts int, offset int) (*model.PostList, *model.AppError)
GetPostsAfter(channelId string, postId string, numPosts int, offset int) (*model.PostList, *model.AppError) GetPostsAfter(channelId string, postId string, numPosts int, offset int) (*model.PostList, *model.AppError)
GetPostsSince(channelId string, time int64, allowFromCache bool) StoreChannel GetPostsSince(channelId string, time int64, allowFromCache bool) (*model.PostList, *model.AppError)
GetEtag(channelId string, allowFromCache bool) string GetEtag(channelId string, allowFromCache bool) string
Search(teamId string, userId string, params *model.SearchParams) StoreChannel Search(teamId string, userId string, params *model.SearchParams) StoreChannel
AnalyticsUserCountsWithPostsByDay(teamId string) (model.AnalyticsRows, *model.AppError) AnalyticsUserCountsWithPostsByDay(teamId string) (model.AnalyticsRows, *model.AppError)

Просмотреть файл

@@ -454,19 +454,28 @@ func (_m *PostStore) GetPostsCreatedAt(channelId string, time int64) ([]*model.P
} }
// GetPostsSince provides a mock function with given fields: channelId, time, allowFromCache // GetPostsSince provides a mock function with given fields: channelId, time, allowFromCache
func (_m *PostStore) GetPostsSince(channelId string, time int64, allowFromCache bool) store.StoreChannel { func (_m *PostStore) GetPostsSince(channelId string, time int64, allowFromCache bool) (*model.PostList, *model.AppError) {
ret := _m.Called(channelId, time, allowFromCache) ret := _m.Called(channelId, time, allowFromCache)
var r0 store.StoreChannel var r0 *model.PostList
if rf, ok := ret.Get(0).(func(string, int64, bool) store.StoreChannel); ok { if rf, ok := ret.Get(0).(func(string, int64, bool) *model.PostList); ok {
r0 = rf(channelId, time, allowFromCache) r0 = rf(channelId, time, allowFromCache)
} else { } else {
if ret.Get(0) != nil { if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel) r0 = ret.Get(0).(*model.PostList)
} }
} }
return r0 var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, int64, bool) *model.AppError); ok {
r1 = rf(channelId, time, allowFromCache)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
} }
// GetRepliesForExport provides a mock function with given fields: parentId // GetRepliesForExport provides a mock function with given fields: parentId

Просмотреть файл

@@ -994,7 +994,7 @@ func testPostStoreGetPostsSince(t *testing.T, ss store.Store) {
o5, err = ss.Post().Save(o5) o5, err = ss.Post().Save(o5)
require.Nil(t, err) require.Nil(t, err)
r1 := (<-ss.Post().GetPostsSince(o1.ChannelId, o1.CreateAt, false)).Data.(*model.PostList) r1, _ := ss.Post().GetPostsSince(o1.ChannelId, o1.CreateAt, false)
if r1.Order[0] != o5.Id { if r1.Order[0] != o5.Id {
t.Fatal("invalid order") t.Fatal("invalid order")
@@ -1020,7 +1020,7 @@ func testPostStoreGetPostsSince(t *testing.T, ss store.Store) {
t.Fatal("Missing parent") t.Fatal("Missing parent")
} }
r2 := (<-ss.Post().GetPostsSince(o1.ChannelId, o5.UpdateAt, true)).Data.(*model.PostList) r2, _ := ss.Post().GetPostsSince(o1.ChannelId, o5.UpdateAt, true)
if len(r2.Order) != 0 { if len(r2.Order) != 0 {
t.Fatal("wrong size ", len(r2.Posts)) t.Fatal("wrong size ", len(r2.Posts))
@@ -1134,7 +1134,7 @@ func testPostStoreSearch(t *testing.T, ss store.Store) {
tt := []struct { tt := []struct {
name string name string
searchParams *model.SearchParams searchParams *model.SearchParams
extectedResultsCount int expectedResultsCount int
expectedMessageResultIds []string expectedMessageResultIds []string
}{ }{
{ {
@@ -1231,7 +1231,7 @@ func testPostStoreSearch(t *testing.T, ss store.Store) {
for _, tc := range tt { for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
result := (<-ss.Post().Search(teamId, userId, tc.searchParams)).Data.(*model.PostList) result := (<-ss.Post().Search(teamId, userId, tc.searchParams)).Data.(*model.PostList)
require.Len(t, result.Order, tc.extectedResultsCount) require.Len(t, result.Order, tc.expectedResultsCount)
for _, expectedMessageResultId := range tc.expectedMessageResultIds { for _, expectedMessageResultId := range tc.expectedMessageResultIds {
assert.Contains(t, result.Order, expectedMessageResultId) assert.Contains(t, result.Order, expectedMessageResultId)
} }