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 удалений

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

@@ -501,40 +501,34 @@ func (s *SqlPostStore) GetPosts(channelId string, offset int, limit int, allowFr
return list, err
}
func (s *SqlPostStore) GetPostsSince(channelId string, time int64, allowFromCache bool) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
if allowFromCache {
// 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.
if cacheItem, ok := s.lastPostTimeCache.Get(channelId); ok && cacheItem.(int64) <= time {
if s.metrics != nil {
s.metrics.IncrementMemCacheHitCounter("Last Post Time")
}
list := model.NewPostList()
result.Data = list
return
} else {
if s.metrics != nil {
s.metrics.IncrementMemCacheMissCounter("Last Post Time")
}
}
} else {
func (s *SqlPostStore) GetPostsSince(channelId string, time int64, allowFromCache bool) (*model.PostList, *model.AppError) {
if allowFromCache {
// 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.
if cacheItem, ok := s.lastPostTimeCache.Get(channelId); ok && cacheItem.(int64) <= time {
if s.metrics != nil {
s.metrics.IncrementMemCacheMissCounter("Last Post Time")
s.metrics.IncrementMemCacheHitCounter("Last Post Time")
}
list := model.NewPostList()
return list, nil
}
}
var posts []*model.Post
_, err := s.GetReplica().Select(&posts,
`(SELECT
*
FROM
Posts
WHERE
(UpdateAt > :Time
AND ChannelId = :ChannelId)
if s.metrics != nil {
s.metrics.IncrementMemCacheMissCounter("Last Post Time")
}
var posts []*model.Post
_, err := s.GetReplica().Select(&posts,
`(SELECT
*
FROM
Posts
WHERE
(UpdateAt > :Time
AND ChannelId = :ChannelId)
LIMIT 1000)
UNION
UNION
(SELECT
*
FROM
@@ -548,34 +542,32 @@ func (s *SqlPostStore) GetPostsSince(channelId string, time int64, allowFromCach
Posts
WHERE
UpdateAt > :Time
AND ChannelId = :ChannelId
LIMIT 1000) temp_tab))
ORDER BY CreateAt DESC`,
map[string]interface{}{"ChannelId": channelId, "Time": time})
AND ChannelId = :ChannelId
LIMIT 1000) temp_tab))
ORDER BY CreateAt DESC`,
map[string]interface{}{"ChannelId": channelId, "Time": time})
if err != nil {
result.Err = model.NewAppError("SqlPostStore.GetPostsSince", "store.sql_post.get_posts_since.app_error", nil, "channelId="+channelId+err.Error(), http.StatusInternalServerError)
} else {
if err != nil {
return nil, model.NewAppError("SqlPostStore.GetPostsSince", "store.sql_post.get_posts_since.app_error", nil, "channelId="+channelId+err.Error(), http.StatusInternalServerError)
}
list := model.NewPostList()
list := model.NewPostList()
var latestUpdate int64 = 0
var latestUpdate int64 = 0
for _, p := range posts {
list.AddPost(p)
if p.UpdateAt > time {
list.AddOrder(p.Id)
}
if latestUpdate < p.UpdateAt {
latestUpdate = p.UpdateAt
}
}
s.lastPostTimeCache.AddWithExpiresInSecs(channelId, latestUpdate, LAST_POST_TIME_CACHE_SEC)
result.Data = list
for _, p := range posts {
list.AddPost(p)
if p.UpdateAt > time {
list.AddOrder(p.Id)
}
})
if latestUpdate < p.UpdateAt {
latestUpdate = p.UpdateAt
}
}
s.lastPostTimeCache.AddWithExpiresInSecs(channelId, latestUpdate, LAST_POST_TIME_CACHE_SEC)
return list, nil
}
func (s *SqlPostStore) GetPostsBefore(channelId string, postId string, limit int, offset int) (*model.PostList, *model.AppError) {