MM-29988 - Update exising Post APIs with collapsed threads (#16503)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
2e1b578ccd
Коммит
b0bddeb5e6
@@ -110,8 +110,8 @@ func getMockStore() *mocks.Store {
|
||||
mockPostStoreEtagResult := fmt.Sprintf("%v.%v", model.CurrentVersion, 1)
|
||||
mockPostStore.On("ClearCaches")
|
||||
mockPostStore.On("InvalidateLastPostTimeCache", "channelId")
|
||||
mockPostStore.On("GetEtag", "channelId", true).Return(mockPostStoreEtagResult)
|
||||
mockPostStore.On("GetEtag", "channelId", false).Return(mockPostStoreEtagResult)
|
||||
mockPostStore.On("GetEtag", "channelId", true, false).Return(mockPostStoreEtagResult)
|
||||
mockPostStore.On("GetEtag", "channelId", false, false).Return(mockPostStoreEtagResult)
|
||||
mockPostStore.On("GetPostsSince", mockPostStoreOptions, true).Return(model.NewPostList(), nil)
|
||||
mockPostStore.On("GetPostsSince", mockPostStoreOptions, false).Return(model.NewPostList(), nil)
|
||||
mockStore.On("Post").Return(&mockPostStore)
|
||||
|
||||
@@ -59,7 +59,7 @@ func (s LocalCachePostStore) InvalidateLastPostTimeCache(channelId string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s LocalCachePostStore) GetEtag(channelId string, allowFromCache bool) string {
|
||||
func (s LocalCachePostStore) GetEtag(channelId string, allowFromCache, collapsedThreads bool) string {
|
||||
if allowFromCache {
|
||||
var lastTime int64
|
||||
if err := s.rootStore.doStandardReadCache(s.rootStore.lastPostTimeCache, channelId, &lastTime); err == nil {
|
||||
@@ -67,7 +67,7 @@ func (s LocalCachePostStore) GetEtag(channelId string, allowFromCache bool) stri
|
||||
}
|
||||
}
|
||||
|
||||
result := s.PostStore.GetEtag(channelId, allowFromCache)
|
||||
result := s.PostStore.GetEtag(channelId, allowFromCache, collapsedThreads)
|
||||
|
||||
splittedResult := strings.Split(result, ".")
|
||||
|
||||
|
||||
@@ -36,11 +36,11 @@ func TestPostStoreLastPostTimeCache(t *testing.T) {
|
||||
|
||||
expectedResult := fmt.Sprintf("%v.%v", model.CurrentVersion, fakeLastTime)
|
||||
|
||||
etag := cachedStore.Post().GetEtag(channelId, true)
|
||||
etag := cachedStore.Post().GetEtag(channelId, true, false)
|
||||
assert.Equal(t, etag, expectedResult)
|
||||
mockStore.Post().(*mocks.PostStore).AssertNumberOfCalls(t, "GetEtag", 1)
|
||||
|
||||
etag = cachedStore.Post().GetEtag(channelId, true)
|
||||
etag = cachedStore.Post().GetEtag(channelId, true, false)
|
||||
assert.Equal(t, etag, expectedResult)
|
||||
mockStore.Post().(*mocks.PostStore).AssertNumberOfCalls(t, "GetEtag", 1)
|
||||
})
|
||||
@@ -51,9 +51,9 @@ func TestPostStoreLastPostTimeCache(t *testing.T) {
|
||||
cachedStore, err := NewLocalCacheLayer(mockStore, nil, nil, mockCacheProvider)
|
||||
require.NoError(t, err)
|
||||
|
||||
cachedStore.Post().GetEtag(channelId, true)
|
||||
cachedStore.Post().GetEtag(channelId, true, false)
|
||||
mockStore.Post().(*mocks.PostStore).AssertNumberOfCalls(t, "GetEtag", 1)
|
||||
cachedStore.Post().GetEtag(channelId, false)
|
||||
cachedStore.Post().GetEtag(channelId, false, false)
|
||||
mockStore.Post().(*mocks.PostStore).AssertNumberOfCalls(t, "GetEtag", 2)
|
||||
})
|
||||
|
||||
@@ -63,10 +63,10 @@ func TestPostStoreLastPostTimeCache(t *testing.T) {
|
||||
cachedStore, err := NewLocalCacheLayer(mockStore, nil, nil, mockCacheProvider)
|
||||
require.NoError(t, err)
|
||||
|
||||
cachedStore.Post().GetEtag(channelId, true)
|
||||
cachedStore.Post().GetEtag(channelId, true, false)
|
||||
mockStore.Post().(*mocks.PostStore).AssertNumberOfCalls(t, "GetEtag", 1)
|
||||
cachedStore.Post().InvalidateLastPostTimeCache(channelId)
|
||||
cachedStore.Post().GetEtag(channelId, true)
|
||||
cachedStore.Post().GetEtag(channelId, true, false)
|
||||
mockStore.Post().(*mocks.PostStore).AssertNumberOfCalls(t, "GetEtag", 2)
|
||||
})
|
||||
|
||||
@@ -76,10 +76,10 @@ func TestPostStoreLastPostTimeCache(t *testing.T) {
|
||||
cachedStore, err := NewLocalCacheLayer(mockStore, nil, nil, mockCacheProvider)
|
||||
require.NoError(t, err)
|
||||
|
||||
cachedStore.Post().GetEtag(channelId, true)
|
||||
cachedStore.Post().GetEtag(channelId, true, false)
|
||||
mockStore.Post().(*mocks.PostStore).AssertNumberOfCalls(t, "GetEtag", 1)
|
||||
cachedStore.Post().ClearCaches()
|
||||
cachedStore.Post().GetEtag(channelId, true)
|
||||
cachedStore.Post().GetEtag(channelId, true, false)
|
||||
mockStore.Post().(*mocks.PostStore).AssertNumberOfCalls(t, "GetEtag", 2)
|
||||
})
|
||||
|
||||
|
||||
@@ -4898,7 +4898,7 @@ func (s *OpenTracingLayerPostStore) Delete(postId string, time int64, deleteByID
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerPostStore) Get(id string, skipFetchThreads bool) (*model.PostList, error) {
|
||||
func (s *OpenTracingLayerPostStore) Get(id string, skipFetchThreads bool, collapsedThreads bool, collapsedThreadsExtended bool) (*model.PostList, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.Get")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -4907,7 +4907,7 @@ func (s *OpenTracingLayerPostStore) Get(id string, skipFetchThreads bool) (*mode
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.PostStore.Get(id, skipFetchThreads)
|
||||
result, err := s.PostStore.Get(id, skipFetchThreads, collapsedThreads, collapsedThreadsExtended)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
@@ -4934,7 +4934,7 @@ func (s *OpenTracingLayerPostStore) GetDirectPostParentsForExportAfter(limit int
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerPostStore) GetEtag(channelId string, allowFromCache bool) string {
|
||||
func (s *OpenTracingLayerPostStore) GetEtag(channelId string, allowFromCache bool, collapsedThreads bool) string {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.GetEtag")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -4943,7 +4943,7 @@ func (s *OpenTracingLayerPostStore) GetEtag(channelId string, allowFromCache boo
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result := s.PostStore.GetEtag(channelId, allowFromCache)
|
||||
result := s.PostStore.GetEtag(channelId, allowFromCache, collapsedThreads)
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -5302,11 +5302,11 @@ func (s *RetryLayerPostStore) Delete(postId string, time int64, deleteByID strin
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerPostStore) Get(id string, skipFetchThreads bool) (*model.PostList, error) {
|
||||
func (s *RetryLayerPostStore) Get(id string, skipFetchThreads bool, collapsedThreads bool, collapsedThreadsExtended bool) (*model.PostList, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.PostStore.Get(id, skipFetchThreads)
|
||||
result, err := s.PostStore.Get(id, skipFetchThreads, collapsedThreads, collapsedThreadsExtended)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
@@ -5342,9 +5342,9 @@ func (s *RetryLayerPostStore) GetDirectPostParentsForExportAfter(limit int, afte
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerPostStore) GetEtag(channelId string, allowFromCache bool) string {
|
||||
func (s *RetryLayerPostStore) GetEtag(channelId string, allowFromCache bool, collapsedThreads bool) string {
|
||||
|
||||
return s.PostStore.GetEtag(channelId, allowFromCache)
|
||||
return s.PostStore.GetEtag(channelId, allowFromCache, collapsedThreads)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ func (s SearchPostStore) Delete(postId string, date int64, deletedByID string) e
|
||||
err := s.PostStore.Delete(postId, date, deletedByID)
|
||||
|
||||
if err == nil {
|
||||
postList, err2 := s.PostStore.Get(postId, true)
|
||||
postList, err2 := s.PostStore.Get(postId, true, false, false)
|
||||
if postList != nil && len(postList.Order) > 0 {
|
||||
if err2 != nil {
|
||||
s.deletePostIndex(postList.Posts[postList.Order[0]])
|
||||
|
||||
@@ -30,6 +30,12 @@ type SqlPostStore struct {
|
||||
maxPostSizeCached int
|
||||
}
|
||||
|
||||
type postWithExtra struct {
|
||||
ThreadReplyCount int64
|
||||
ThreadParticipants model.StringArray
|
||||
model.Post
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) ClearCaches() {
|
||||
}
|
||||
|
||||
@@ -418,8 +424,40 @@ func (s *SqlPostStore) GetFlaggedPostsForChannel(userId, channelId string, offse
|
||||
|
||||
return pl, nil
|
||||
}
|
||||
func (s *SqlPostStore) getPostWithCollapsedThreads(id string, extended bool) (*model.PostList, error) {
|
||||
if len(id) == 0 {
|
||||
return nil, store.NewErrInvalidInput("Post", "id", id)
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) Get(id string, skipFetchThreads bool) (*model.PostList, error) {
|
||||
var columns []string
|
||||
for _, c := range postSliceColumns() {
|
||||
columns = append(columns, "Posts."+c)
|
||||
}
|
||||
columns = append(columns, "COALESCE(Threads.ReplyCount, 0) as ThreadReplyCount", "COALESCE(Threads.LastReplyAt, 0) as LastReplyAt", "COALESCE(Threads.Participants, '[]') as ThreadParticipants")
|
||||
var post postWithExtra
|
||||
|
||||
postFetchQuery, args, _ := s.getQueryBuilder().
|
||||
Select(columns...).
|
||||
From("Posts").
|
||||
LeftJoin("Threads ON Threads.PostId = Id").
|
||||
Where(sq.Eq{"DeleteAt": 0}).
|
||||
Where(sq.Eq{"Id": id}).ToSql()
|
||||
|
||||
err := s.GetReplica().SelectOne(&post, postFetchQuery, args...)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Post", id)
|
||||
}
|
||||
|
||||
return nil, errors.Wrapf(err, "failed to get Post with id=%s", id)
|
||||
}
|
||||
return s.prepareThreadedResponse([]*postWithExtra{&post}, extended, false)
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) Get(id string, skipFetchThreads, collapsedThreads, collapsedThreadsExtended bool) (*model.PostList, error) {
|
||||
if collapsedThreads {
|
||||
return s.getPostWithCollapsedThreads(id, collapsedThreadsExtended)
|
||||
}
|
||||
pl := model.NewPostList()
|
||||
|
||||
if len(id) == 0 {
|
||||
@@ -484,9 +522,14 @@ type etagPosts struct {
|
||||
func (s *SqlPostStore) InvalidateLastPostTimeCache(channelId string) {
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) GetEtag(channelId string, allowFromCache bool) string {
|
||||
func (s *SqlPostStore) GetEtag(channelId string, allowFromCache, collapsedThreads bool) string {
|
||||
q := s.getQueryBuilder().Select("Id", "UpdateAt").From("Posts").Where(sq.Eq{"ChannelId": channelId}).OrderBy("UpdateAt DESC").Limit(1)
|
||||
if collapsedThreads {
|
||||
q.Where(sq.Eq{"RootId": ""})
|
||||
}
|
||||
sql, args, _ := q.ToSql()
|
||||
var et etagPosts
|
||||
err := s.GetReplica().SelectOne(&et, "SELECT Id, UpdateAt FROM Posts WHERE ChannelId = :ChannelId ORDER BY UpdateAt DESC LIMIT 1", map[string]interface{}{"ChannelId": channelId})
|
||||
err := s.GetReplica().SelectOne(&et, sql, args...)
|
||||
var result string
|
||||
if err != nil {
|
||||
result = fmt.Sprintf("%v.%v", model.CurrentVersion, model.GetMillis())
|
||||
@@ -616,10 +659,102 @@ func (s *SqlPostStore) PermanentDeleteByChannel(channelId string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) prepareThreadedResponse(posts []*postWithExtra, extended, reversed bool) (*model.PostList, error) {
|
||||
list := model.NewPostList()
|
||||
var userIds []string
|
||||
userIdMap := map[string]bool{}
|
||||
for _, thread := range posts {
|
||||
for _, participantId := range thread.ThreadParticipants {
|
||||
if _, ok := userIdMap[participantId]; !ok {
|
||||
userIdMap[participantId] = true
|
||||
userIds = append(userIds, participantId)
|
||||
}
|
||||
}
|
||||
}
|
||||
var users []*model.User
|
||||
if extended {
|
||||
var err error
|
||||
users, err = s.User().GetProfileByIds(userIds, &store.UserGetByIdsOpts{}, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
for _, userId := range userIds {
|
||||
users = append(users, &model.User{Id: userId})
|
||||
}
|
||||
}
|
||||
processPost := func(p *postWithExtra) error {
|
||||
p.Post.ReplyCount = p.ThreadReplyCount
|
||||
for _, th := range p.ThreadParticipants {
|
||||
var participant *model.User
|
||||
for _, u := range users {
|
||||
if u.Id == th {
|
||||
participant = u
|
||||
break
|
||||
}
|
||||
}
|
||||
if participant == nil {
|
||||
return errors.New("cannot find thread participant with id=" + th)
|
||||
}
|
||||
p.Post.Participants = append(p.Post.Participants, participant)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
l := len(posts)
|
||||
for i := range posts {
|
||||
idx := i
|
||||
// We need to flip the order if we selected backwards
|
||||
|
||||
if reversed {
|
||||
idx = l - i - 1
|
||||
}
|
||||
if err := processPost(posts[idx]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list.AddPost(&posts[idx].Post)
|
||||
list.AddOrder(posts[idx].Id)
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) getPostsCollapsedThreads(options model.GetPostsOptions) (*model.PostList, error) {
|
||||
var columns []string
|
||||
for _, c := range postSliceColumns() {
|
||||
columns = append(columns, "Posts."+c)
|
||||
}
|
||||
columns = append(columns, "COALESCE(Threads.ReplyCount, 0) as ThreadReplyCount", "COALESCE(Threads.LastReplyAt, 0) as LastReplyAt", "COALESCE(Threads.Participants, '[]') as ThreadParticipants")
|
||||
var posts []*postWithExtra
|
||||
offset := options.PerPage * options.Page
|
||||
|
||||
postFetchQuery, args, _ := s.getQueryBuilder().
|
||||
Select(columns...).
|
||||
From("Posts").
|
||||
LeftJoin("Threads ON Threads.PostId = Id").
|
||||
Where(sq.Eq{"DeleteAt": 0}).
|
||||
Where(sq.Eq{"Posts.ChannelId": options.ChannelId}).
|
||||
Where(sq.Eq{"RootId": ""}).
|
||||
Limit(uint64(options.PerPage)).
|
||||
Offset(uint64(offset)).
|
||||
OrderBy("CreateAt DESC").ToSql()
|
||||
|
||||
_, err := s.GetReplica().Select(&posts, postFetchQuery, args...)
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Posts with channelId=%s", options.ChannelId)
|
||||
}
|
||||
|
||||
return s.prepareThreadedResponse(posts, options.CollapsedThreadsExtended, false)
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) GetPosts(options model.GetPostsOptions, _ bool) (*model.PostList, error) {
|
||||
if options.PerPage > 1000 {
|
||||
return nil, store.NewErrInvalidInput("Post", "<options.PerPage>", options.PerPage)
|
||||
}
|
||||
if options.CollapsedThreads {
|
||||
return s.getPostsCollapsedThreads(options)
|
||||
}
|
||||
offset := options.PerPage * options.Page
|
||||
|
||||
rpc := make(chan store.StoreResult, 1)
|
||||
@@ -664,7 +799,36 @@ func (s *SqlPostStore) GetPosts(options model.GetPostsOptions, _ bool) (*model.P
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) getPostsSinceCollapsedThreads(options model.GetPostsSinceOptions) (*model.PostList, error) {
|
||||
var columns []string
|
||||
for _, c := range postSliceColumns() {
|
||||
columns = append(columns, "Posts."+c)
|
||||
}
|
||||
columns = append(columns, "COALESCE(Threads.ReplyCount, 0) as ThreadReplyCount", "COALESCE(Threads.LastReplyAt, 0) as LastReplyAt", "COALESCE(Threads.Participants, '[]') as ThreadParticipants")
|
||||
var posts []*postWithExtra
|
||||
|
||||
postFetchQuery, args, _ := s.getQueryBuilder().
|
||||
Select(columns...).
|
||||
From("Posts").
|
||||
LeftJoin("Threads ON Threads.PostId = Id").
|
||||
Where(sq.Eq{"DeleteAt": 0}).
|
||||
Where(sq.Eq{"Posts.ChannelId": options.ChannelId}).
|
||||
Where(sq.Gt{"UpdateAt": options.Time}).
|
||||
Where(sq.Eq{"RootId": ""}).
|
||||
OrderBy("CreateAt DESC").ToSql()
|
||||
|
||||
_, err := s.GetReplica().Select(&posts, postFetchQuery, args...)
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Posts with channelId=%s", options.ChannelId)
|
||||
}
|
||||
return s.prepareThreadedResponse(posts, options.CollapsedThreadsExtended, false)
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) GetPostsSince(options model.GetPostsSinceOptions, allowFromCache bool) (*model.PostList, error) {
|
||||
if options.CollapsedThreads {
|
||||
return s.getPostsSinceCollapsedThreads(options)
|
||||
}
|
||||
var posts []*model.Post
|
||||
|
||||
replyCountQuery1 := ""
|
||||
@@ -753,7 +917,8 @@ func (s *SqlPostStore) getPostsAround(before bool, options model.GetPostsOptions
|
||||
}
|
||||
|
||||
offset := options.Page * options.PerPage
|
||||
var posts, parents []*model.Post
|
||||
var posts []*postWithExtra
|
||||
var parents []*model.Post
|
||||
|
||||
var direction string
|
||||
var sort string
|
||||
@@ -771,20 +936,30 @@ func (s *SqlPostStore) getPostsAround(before bool, options model.GetPostsOptions
|
||||
if s.DriverName() == model.DATABASE_DRIVER_MYSQL {
|
||||
table += " USE INDEX(idx_posts_channel_id_delete_at_create_at)"
|
||||
}
|
||||
|
||||
columns := []string{"p.*"}
|
||||
if options.CollapsedThreads {
|
||||
columns = append(columns, "COALESCE(Threads.ReplyCount, 0) as ThreadReplyCount", "COALESCE(Threads.LastReplyAt, 0) as LastReplyAt", "COALESCE(Threads.Participants, '[]') as ThreadParticipants")
|
||||
}
|
||||
query := s.getQueryBuilder().Select(columns...)
|
||||
replyCountSubQuery := s.getQueryBuilder().Select("COUNT(Posts.Id)").From("Posts").Where(sq.Expr("Posts.RootId = (CASE WHEN p.RootId = '' THEN p.Id ELSE p.RootId END) AND Posts.DeleteAt = 0"))
|
||||
query := s.getQueryBuilder().Select("p.*")
|
||||
query = query.Column(sq.Alias(replyCountSubQuery, "ReplyCount"))
|
||||
|
||||
conditions := sq.And{
|
||||
sq.Expr(`CreateAt `+direction+` (SELECT CreateAt FROM Posts WHERE Id = ?)`, options.PostId),
|
||||
sq.Eq{"p.ChannelId": options.ChannelId},
|
||||
sq.Eq{"DeleteAt": int(0)},
|
||||
}
|
||||
if options.CollapsedThreads {
|
||||
conditions = append(conditions, sq.Eq{"RootId": ""})
|
||||
query = query.LeftJoin("Threads ON Threads.PostId = p.Id")
|
||||
} else {
|
||||
query = query.Column(sq.Alias(replyCountSubQuery, "ReplyCount"))
|
||||
}
|
||||
query = query.From(table).
|
||||
Where(sq.And{
|
||||
sq.Expr(`CreateAt `+direction+` (SELECT CreateAt FROM Posts WHERE Id = ?)`, options.PostId),
|
||||
sq.Eq{"ChannelId": options.ChannelId},
|
||||
sq.Eq{"DeleteAt": int(0)},
|
||||
}).
|
||||
Where(conditions).
|
||||
// Adding ChannelId and DeleteAt order columns
|
||||
// to let mysql choose the "idx_posts_channel_id_delete_at_create_at" index always.
|
||||
// See MM-24170.
|
||||
OrderBy("ChannelId", "DeleteAt", "CreateAt "+sort).
|
||||
OrderBy("p.ChannelId", "DeleteAt", "CreateAt "+sort).
|
||||
Limit(uint64(options.PerPage)).
|
||||
Offset(uint64(offset))
|
||||
|
||||
@@ -797,7 +972,7 @@ func (s *SqlPostStore) getPostsAround(before bool, options model.GetPostsOptions
|
||||
return nil, errors.Wrapf(err, "failed to find Posts with channelId=%s", options.ChannelId)
|
||||
}
|
||||
|
||||
if len(posts) > 0 {
|
||||
if !options.CollapsedThreads && len(posts) > 0 {
|
||||
rootIds := []string{}
|
||||
for _, post := range posts {
|
||||
rootIds = append(rootIds, post.Id)
|
||||
@@ -822,31 +997,20 @@ func (s *SqlPostStore) getPostsAround(before bool, options model.GetPostsOptions
|
||||
}).
|
||||
OrderBy("CreateAt DESC")
|
||||
|
||||
rootQueryString, rootArgs, err := rootQuery.ToSql()
|
||||
rootQueryString, rootArgs, nErr := rootQuery.ToSql()
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "post_tosql")
|
||||
if nErr != nil {
|
||||
return nil, errors.Wrap(nErr, "post_tosql")
|
||||
}
|
||||
_, err = s.GetMaster().Select(&parents, rootQueryString, rootArgs...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Posts with channelId=%s", options.ChannelId)
|
||||
_, nErr = s.GetMaster().Select(&parents, rootQueryString, rootArgs...)
|
||||
if nErr != nil {
|
||||
return nil, errors.Wrapf(nErr, "failed to find Posts with channelId=%s", options.ChannelId)
|
||||
}
|
||||
}
|
||||
|
||||
list := model.NewPostList()
|
||||
|
||||
// We need to flip the order if we selected backwards
|
||||
if before {
|
||||
for _, p := range posts {
|
||||
list.AddPost(p)
|
||||
list.AddOrder(p.Id)
|
||||
}
|
||||
} else {
|
||||
l := len(posts)
|
||||
for i := range posts {
|
||||
list.AddPost(posts[l-i-1])
|
||||
list.AddOrder(posts[l-i-1].Id)
|
||||
}
|
||||
list, err := s.prepareThreadedResponse(posts, options.CollapsedThreadsExtended, !before)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, p := range parents {
|
||||
|
||||
@@ -234,8 +234,9 @@ func (s *SqlThreadStore) GetThreadsForUser(userId, teamId string, opts model.Get
|
||||
}
|
||||
var users []*model.User
|
||||
if opts.Extended {
|
||||
query, args, _ := s.getQueryBuilder().Select("*").From("Users").Where(sq.Eq{"Id": userIds}).ToSql()
|
||||
if _, err := s.GetReplica().Select(&users, query, args...); err != nil {
|
||||
var err error
|
||||
users, err = s.User().GetProfileByIds(userIds, &store.UserGetByIdsOpts{}, true)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get threads for user id=%s", userId)
|
||||
}
|
||||
} else {
|
||||
@@ -414,6 +415,18 @@ func (s *SqlThreadStore) CreateMembershipIfNeeded(userId, postId string, followi
|
||||
LastUpdated: now,
|
||||
UnreadMentions: int64(mentions),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
thread, err := s.Get(postId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !thread.Participants.Contains(userId) {
|
||||
thread.Participants = append(thread.Participants, userId)
|
||||
_, err = s.Update(thread)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -964,6 +964,7 @@ func upgradeDatabaseToVersion532(sqlStore *SqlStore) {
|
||||
// if shouldPerformUpgrade(sqlStore, Version5310, Version5320) {
|
||||
// allow 10 files per post
|
||||
sqlStore.AlterColumnTypeIfExists("Posts", "FileIds", "text", "varchar(300)")
|
||||
sqlStore.CreateColumnIfNotExists("ThreadMemberships", "UnreadMentions", "bigint", "bigint", "0")
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("Channels", "Shared", "tinyint(1)", "boolean")
|
||||
sqlStore.CreateColumnIfNotExists("ThreadMemberships", "UnreadMentions", "bigint", "bigint", "0")
|
||||
// saveSchemaVersion(sqlStore, Version5320)
|
||||
|
||||
@@ -272,7 +272,7 @@ type PostStore interface {
|
||||
SaveMultiple(posts []*model.Post) ([]*model.Post, int, error)
|
||||
Save(post *model.Post) (*model.Post, error)
|
||||
Update(newPost *model.Post, oldPost *model.Post) (*model.Post, error)
|
||||
Get(id string, skipFetchThreads bool) (*model.PostList, error)
|
||||
Get(id string, skipFetchThreads, collapsedThreads, collapsedThreadsExtended bool) (*model.PostList, error)
|
||||
GetSingle(id string) (*model.Post, error)
|
||||
Delete(postId string, time int64, deleteByID string) error
|
||||
PermanentDeleteByUser(userId string) error
|
||||
@@ -288,7 +288,7 @@ type PostStore interface {
|
||||
GetPostAfterTime(channelId string, time int64) (*model.Post, error)
|
||||
GetPostIdAfterTime(channelId string, time int64) (string, error)
|
||||
GetPostIdBeforeTime(channelId string, time int64) (string, error)
|
||||
GetEtag(channelId string, allowFromCache bool) string
|
||||
GetEtag(channelId string, allowFromCache bool, collapsedThreads bool) string
|
||||
Search(teamId string, userId string, params *model.SearchParams) (*model.PostList, error)
|
||||
AnalyticsUserCountsWithPostsByDay(teamId string) (model.AnalyticsRows, error)
|
||||
AnalyticsPostCountsByDay(options *model.AnalyticsPostCountsOptions) (model.AnalyticsRows, error)
|
||||
|
||||
@@ -100,13 +100,13 @@ func (_m *PostStore) Delete(postId string, time int64, deleteByID string) error
|
||||
return r0
|
||||
}
|
||||
|
||||
// Get provides a mock function with given fields: id, skipFetchThreads
|
||||
func (_m *PostStore) Get(id string, skipFetchThreads bool) (*model.PostList, error) {
|
||||
ret := _m.Called(id, skipFetchThreads)
|
||||
// Get provides a mock function with given fields: id, skipFetchThreads, collapsedThreads, collapsedThreadsExtended
|
||||
func (_m *PostStore) Get(id string, skipFetchThreads bool, collapsedThreads bool, collapsedThreadsExtended bool) (*model.PostList, error) {
|
||||
ret := _m.Called(id, skipFetchThreads, collapsedThreads, collapsedThreadsExtended)
|
||||
|
||||
var r0 *model.PostList
|
||||
if rf, ok := ret.Get(0).(func(string, bool) *model.PostList); ok {
|
||||
r0 = rf(id, skipFetchThreads)
|
||||
if rf, ok := ret.Get(0).(func(string, bool, bool, bool) *model.PostList); ok {
|
||||
r0 = rf(id, skipFetchThreads, collapsedThreads, collapsedThreadsExtended)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.PostList)
|
||||
@@ -114,8 +114,8 @@ func (_m *PostStore) Get(id string, skipFetchThreads bool) (*model.PostList, err
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string, bool) error); ok {
|
||||
r1 = rf(id, skipFetchThreads)
|
||||
if rf, ok := ret.Get(1).(func(string, bool, bool, bool) error); ok {
|
||||
r1 = rf(id, skipFetchThreads, collapsedThreads, collapsedThreadsExtended)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
@@ -146,13 +146,13 @@ func (_m *PostStore) GetDirectPostParentsForExportAfter(limit int, afterId strin
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetEtag provides a mock function with given fields: channelId, allowFromCache
|
||||
func (_m *PostStore) GetEtag(channelId string, allowFromCache bool) string {
|
||||
ret := _m.Called(channelId, allowFromCache)
|
||||
// GetEtag provides a mock function with given fields: channelId, allowFromCache, collapsedThreads
|
||||
func (_m *PostStore) GetEtag(channelId string, allowFromCache bool, collapsedThreads bool) string {
|
||||
ret := _m.Called(channelId, allowFromCache, collapsedThreads)
|
||||
|
||||
var r0 string
|
||||
if rf, ok := ret.Get(0).(func(string, bool) string); ok {
|
||||
r0 = rf(channelId, allowFromCache)
|
||||
if rf, ok := ret.Get(0).(func(string, bool, bool) string); ok {
|
||||
r0 = rf(channelId, allowFromCache, collapsedThreads)
|
||||
} else {
|
||||
r0 = ret.Get(0).(string)
|
||||
}
|
||||
|
||||
@@ -407,23 +407,23 @@ func testPostStoreGet(t *testing.T, ss store.Store) {
|
||||
o1.UserId = model.NewId()
|
||||
o1.Message = "zz" + model.NewId() + "b"
|
||||
|
||||
etag1 := ss.Post().GetEtag(o1.ChannelId, false)
|
||||
etag1 := ss.Post().GetEtag(o1.ChannelId, false, false)
|
||||
require.Equal(t, 0, strings.Index(etag1, model.CurrentVersion+"."), "Invalid Etag")
|
||||
|
||||
o1, err := ss.Post().Save(o1)
|
||||
require.Nil(t, err)
|
||||
|
||||
etag2 := ss.Post().GetEtag(o1.ChannelId, false)
|
||||
etag2 := ss.Post().GetEtag(o1.ChannelId, false, false)
|
||||
require.Equal(t, 0, strings.Index(etag2, fmt.Sprintf("%v.%v", model.CurrentVersion, o1.UpdateAt)), "Invalid Etag")
|
||||
|
||||
r1, err := ss.Post().Get(o1.Id, false)
|
||||
r1, err := ss.Post().Get(o1.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, r1.Posts[o1.Id].CreateAt, o1.CreateAt, "invalid returned post")
|
||||
|
||||
_, err = ss.Post().Get("123", false)
|
||||
_, err = ss.Post().Get("123", false, false, false)
|
||||
require.NotNil(t, err, "Missing id should have failed")
|
||||
|
||||
_, err = ss.Post().Get("", false)
|
||||
_, err = ss.Post().Get("", false, false, false)
|
||||
require.NotNil(t, err, "should fail for blank post ids")
|
||||
}
|
||||
|
||||
@@ -468,15 +468,15 @@ func testPostStoreUpdate(t *testing.T, ss store.Store) {
|
||||
o3, err = ss.Post().Save(o3)
|
||||
require.Nil(t, err)
|
||||
|
||||
r1, err := ss.Post().Get(o1.Id, false)
|
||||
r1, err := ss.Post().Get(o1.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
ro1 := r1.Posts[o1.Id]
|
||||
|
||||
r2, err := ss.Post().Get(o1.Id, false)
|
||||
r2, err := ss.Post().Get(o1.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
ro2 := r2.Posts[o2.Id]
|
||||
|
||||
r3, err := ss.Post().Get(o3.Id, false)
|
||||
r3, err := ss.Post().Get(o3.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
ro3 := r3.Posts[o3.Id]
|
||||
|
||||
@@ -487,7 +487,7 @@ func testPostStoreUpdate(t *testing.T, ss store.Store) {
|
||||
_, err = ss.Post().Update(o1a, ro1)
|
||||
require.Nil(t, err)
|
||||
|
||||
r1, err = ss.Post().Get(o1.Id, false)
|
||||
r1, err = ss.Post().Get(o1.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
ro1a := r1.Posts[o1.Id]
|
||||
@@ -498,7 +498,7 @@ func testPostStoreUpdate(t *testing.T, ss store.Store) {
|
||||
_, err = ss.Post().Update(o2a, ro2)
|
||||
require.Nil(t, err)
|
||||
|
||||
r2, err = ss.Post().Get(o1.Id, false)
|
||||
r2, err = ss.Post().Get(o1.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
ro2a := r2.Posts[o2.Id]
|
||||
|
||||
@@ -509,7 +509,7 @@ func testPostStoreUpdate(t *testing.T, ss store.Store) {
|
||||
_, err = ss.Post().Update(o3a, ro3)
|
||||
require.Nil(t, err)
|
||||
|
||||
r3, err = ss.Post().Get(o3.Id, false)
|
||||
r3, err = ss.Post().Get(o3.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
ro3a := r3.Posts[o3.Id]
|
||||
|
||||
@@ -525,7 +525,7 @@ func testPostStoreUpdate(t *testing.T, ss store.Store) {
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
r4, err := ss.Post().Get(o4.Id, false)
|
||||
r4, err := ss.Post().Get(o4.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
ro4 := r4.Posts[o4.Id]
|
||||
|
||||
@@ -535,7 +535,7 @@ func testPostStoreUpdate(t *testing.T, ss store.Store) {
|
||||
_, err = ss.Post().Update(o4a, ro4)
|
||||
require.Nil(t, err)
|
||||
|
||||
r4, err = ss.Post().Get(o4.Id, false)
|
||||
r4, err = ss.Post().Get(o4.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
ro4a := r4.Posts[o4.Id]
|
||||
@@ -550,13 +550,13 @@ func testPostStoreDelete(t *testing.T, ss store.Store) {
|
||||
o1.Message = "zz" + model.NewId() + "b"
|
||||
deleteByID := model.NewId()
|
||||
|
||||
etag1 := ss.Post().GetEtag(o1.ChannelId, false)
|
||||
etag1 := ss.Post().GetEtag(o1.ChannelId, false, false)
|
||||
require.Equal(t, 0, strings.Index(etag1, model.CurrentVersion+"."), "Invalid Etag")
|
||||
|
||||
o1, err := ss.Post().Save(o1)
|
||||
require.Nil(t, err)
|
||||
|
||||
r1, err := ss.Post().Get(o1.Id, false)
|
||||
r1, err := ss.Post().Get(o1.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, r1.Posts[o1.Id].CreateAt, o1.CreateAt, "invalid returned post")
|
||||
|
||||
@@ -569,10 +569,10 @@ func testPostStoreDelete(t *testing.T, ss store.Store) {
|
||||
|
||||
assert.Equal(t, deleteByID, actual, "Expected (*Post).Props[model.POST_PROPS_DELETE_BY] to be %v but got %v.", deleteByID, actual)
|
||||
|
||||
r3, err := ss.Post().Get(o1.Id, false)
|
||||
r3, err := ss.Post().Get(o1.Id, false, false, false)
|
||||
require.NotNil(t, err, "Missing id should have failed - PostList %v", r3)
|
||||
|
||||
etag2 := ss.Post().GetEtag(o1.ChannelId, false)
|
||||
etag2 := ss.Post().GetEtag(o1.ChannelId, false, false)
|
||||
require.Equal(t, 0, strings.Index(etag2, model.CurrentVersion+"."), "Invalid Etag")
|
||||
}
|
||||
|
||||
@@ -596,10 +596,10 @@ func testPostStoreDelete1Level(t *testing.T, ss store.Store) {
|
||||
err = ss.Post().Delete(o1.Id, model.GetMillis(), "")
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = ss.Post().Get(o1.Id, false)
|
||||
_, err = ss.Post().Get(o1.Id, false, false, false)
|
||||
require.NotNil(t, err, "Deleted id should have failed")
|
||||
|
||||
_, err = ss.Post().Get(o2.Id, false)
|
||||
_, err = ss.Post().Get(o2.Id, false, false, false)
|
||||
require.NotNil(t, err, "Deleted id should have failed")
|
||||
}
|
||||
|
||||
@@ -639,16 +639,16 @@ func testPostStoreDelete2Level(t *testing.T, ss store.Store) {
|
||||
err = ss.Post().Delete(o1.Id, model.GetMillis(), "")
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = ss.Post().Get(o1.Id, false)
|
||||
_, err = ss.Post().Get(o1.Id, false, false, false)
|
||||
require.NotNil(t, err, "Deleted id should have failed")
|
||||
|
||||
_, err = ss.Post().Get(o2.Id, false)
|
||||
_, err = ss.Post().Get(o2.Id, false, false, false)
|
||||
require.NotNil(t, err, "Deleted id should have failed")
|
||||
|
||||
_, err = ss.Post().Get(o3.Id, false)
|
||||
_, err = ss.Post().Get(o3.Id, false, false, false)
|
||||
require.NotNil(t, err, "Deleted id should have failed")
|
||||
|
||||
_, err = ss.Post().Get(o4.Id, false)
|
||||
_, err = ss.Post().Get(o4.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
@@ -679,16 +679,16 @@ func testPostStorePermDelete1Level(t *testing.T, ss store.Store) {
|
||||
err2 := ss.Post().PermanentDeleteByUser(o2.UserId)
|
||||
require.Nil(t, err2)
|
||||
|
||||
_, err = ss.Post().Get(o1.Id, false)
|
||||
_, err = ss.Post().Get(o1.Id, false, false, false)
|
||||
require.Nil(t, err, "Deleted id shouldn't have failed")
|
||||
|
||||
_, err = ss.Post().Get(o2.Id, false)
|
||||
_, err = ss.Post().Get(o2.Id, false, false, false)
|
||||
require.NotNil(t, err, "Deleted id should have failed")
|
||||
|
||||
err = ss.Post().PermanentDeleteByChannel(o3.ChannelId)
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = ss.Post().Get(o3.Id, false)
|
||||
_, err = ss.Post().Get(o3.Id, false, false, false)
|
||||
require.NotNil(t, err, "Deleted id should have failed")
|
||||
}
|
||||
|
||||
@@ -719,13 +719,13 @@ func testPostStorePermDelete1Level2(t *testing.T, ss store.Store) {
|
||||
err2 := ss.Post().PermanentDeleteByUser(o1.UserId)
|
||||
require.Nil(t, err2)
|
||||
|
||||
_, err = ss.Post().Get(o1.Id, false)
|
||||
_, err = ss.Post().Get(o1.Id, false, false, false)
|
||||
require.NotNil(t, err, "Deleted id should have failed")
|
||||
|
||||
_, err = ss.Post().Get(o2.Id, false)
|
||||
_, err = ss.Post().Get(o2.Id, false, false, false)
|
||||
require.NotNil(t, err, "Deleted id should have failed")
|
||||
|
||||
_, err = ss.Post().Get(o3.Id, false)
|
||||
_, err = ss.Post().Get(o3.Id, false, false, false)
|
||||
require.Nil(t, err, "Deleted id should have failed")
|
||||
}
|
||||
|
||||
@@ -755,7 +755,7 @@ func testPostStoreGetWithChildren(t *testing.T, ss store.Store) {
|
||||
o3, err = ss.Post().Save(o3)
|
||||
require.Nil(t, err)
|
||||
|
||||
pl, err := ss.Post().Get(o1.Id, false)
|
||||
pl, err := ss.Post().Get(o1.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Len(t, pl.Posts, 3, "invalid returned post")
|
||||
@@ -763,7 +763,7 @@ func testPostStoreGetWithChildren(t *testing.T, ss store.Store) {
|
||||
dErr := ss.Post().Delete(o3.Id, model.GetMillis(), "")
|
||||
require.Nil(t, dErr)
|
||||
|
||||
pl, err = ss.Post().Get(o1.Id, false)
|
||||
pl, err = ss.Post().Get(o1.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Len(t, pl.Posts, 2, "invalid returned post")
|
||||
@@ -771,7 +771,7 @@ func testPostStoreGetWithChildren(t *testing.T, ss store.Store) {
|
||||
dErr = ss.Post().Delete(o2.Id, model.GetMillis(), "")
|
||||
require.Nil(t, dErr)
|
||||
|
||||
pl, err = ss.Post().Get(o1.Id, false)
|
||||
pl, err = ss.Post().Get(o1.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Len(t, pl.Posts, 1, "invalid returned post")
|
||||
@@ -1181,6 +1181,101 @@ func testPostStoreGetPostsBeforeAfter(t *testing.T, ss store.Store) {
|
||||
}, postList.Posts)
|
||||
})
|
||||
})
|
||||
t.Run("with threads (collapsedThreads)", func(t *testing.T) {
|
||||
channelId := model.NewId()
|
||||
userId := model.NewId()
|
||||
|
||||
// This creates a series of posts that looks like:
|
||||
// post1
|
||||
// post2
|
||||
// post3 (in response to post1)
|
||||
// post4 (in response to post2)
|
||||
// post5
|
||||
// post6 (in response to post2)
|
||||
|
||||
post1, err := ss.Post().Save(&model.Post{
|
||||
ChannelId: channelId,
|
||||
UserId: userId,
|
||||
Message: "post1",
|
||||
})
|
||||
require.Nil(t, err)
|
||||
post1.ReplyCount = 1
|
||||
time.Sleep(time.Millisecond)
|
||||
|
||||
post2, err := ss.Post().Save(&model.Post{
|
||||
ChannelId: channelId,
|
||||
UserId: userId,
|
||||
Message: "post2",
|
||||
})
|
||||
require.Nil(t, err)
|
||||
post2.ReplyCount = 2
|
||||
time.Sleep(time.Millisecond)
|
||||
|
||||
post3, err := ss.Post().Save(&model.Post{
|
||||
ChannelId: channelId,
|
||||
UserId: userId,
|
||||
ParentId: post1.Id,
|
||||
RootId: post1.Id,
|
||||
Message: "post3",
|
||||
})
|
||||
require.Nil(t, err)
|
||||
post3.ReplyCount = 1
|
||||
time.Sleep(time.Millisecond)
|
||||
|
||||
post4, err := ss.Post().Save(&model.Post{
|
||||
ChannelId: channelId,
|
||||
UserId: userId,
|
||||
RootId: post2.Id,
|
||||
ParentId: post2.Id,
|
||||
Message: "post4",
|
||||
})
|
||||
require.Nil(t, err)
|
||||
post4.ReplyCount = 2
|
||||
time.Sleep(time.Millisecond)
|
||||
|
||||
post5, err := ss.Post().Save(&model.Post{
|
||||
ChannelId: channelId,
|
||||
UserId: userId,
|
||||
Message: "post5",
|
||||
})
|
||||
require.Nil(t, err)
|
||||
time.Sleep(time.Millisecond)
|
||||
|
||||
post6, err := ss.Post().Save(&model.Post{
|
||||
ChannelId: channelId,
|
||||
UserId: userId,
|
||||
ParentId: post2.Id,
|
||||
RootId: post2.Id,
|
||||
Message: "post6",
|
||||
})
|
||||
post6.ReplyCount = 2
|
||||
require.Nil(t, err)
|
||||
|
||||
// Adding a post to a thread changes the UpdateAt timestamp of the parent post
|
||||
post1.UpdateAt = post3.UpdateAt
|
||||
post2.UpdateAt = post6.UpdateAt
|
||||
|
||||
t.Run("should return each root post before a post", func(t *testing.T) {
|
||||
postList, err := ss.Post().GetPostsBefore(model.GetPostsOptions{ChannelId: channelId, PostId: post4.Id, PerPage: 2, CollapsedThreads: true})
|
||||
assert.Nil(t, err)
|
||||
|
||||
assert.Equal(t, []string{post2.Id, post1.Id}, postList.Order)
|
||||
})
|
||||
|
||||
t.Run("should return each root post before a post with limit", func(t *testing.T) {
|
||||
postList, err := ss.Post().GetPostsBefore(model.GetPostsOptions{ChannelId: channelId, PostId: post4.Id, PerPage: 1, CollapsedThreads: true})
|
||||
assert.Nil(t, err)
|
||||
|
||||
assert.Equal(t, []string{post2.Id}, postList.Order)
|
||||
})
|
||||
|
||||
t.Run("should return each root after a post", func(t *testing.T) {
|
||||
postList, err := ss.Post().GetPostsAfter(model.GetPostsOptions{ChannelId: channelId, PostId: post4.Id, PerPage: 2, CollapsedThreads: true})
|
||||
require.Nil(t, err)
|
||||
|
||||
assert.Equal(t, []string{post5.Id}, postList.Order)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func testPostStoreGetPostsSince(t *testing.T, ss store.Store) {
|
||||
@@ -2146,23 +2241,23 @@ func testPostStoreOverwriteMultiple(t *testing.T, ss store.Store) {
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
r1, err := ss.Post().Get(o1.Id, false)
|
||||
r1, err := ss.Post().Get(o1.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
ro1 := r1.Posts[o1.Id]
|
||||
|
||||
r2, err := ss.Post().Get(o2.Id, false)
|
||||
r2, err := ss.Post().Get(o2.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
ro2 := r2.Posts[o2.Id]
|
||||
|
||||
r3, err := ss.Post().Get(o3.Id, false)
|
||||
r3, err := ss.Post().Get(o3.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
ro3 := r3.Posts[o3.Id]
|
||||
|
||||
r4, err := ss.Post().Get(o4.Id, false)
|
||||
r4, err := ss.Post().Get(o4.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
ro4 := r4.Posts[o4.Id]
|
||||
|
||||
r5, err := ss.Post().Get(o5.Id, false)
|
||||
r5, err := ss.Post().Get(o5.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
ro5 := r5.Posts[o5.Id]
|
||||
|
||||
@@ -2188,15 +2283,15 @@ func testPostStoreOverwriteMultiple(t *testing.T, ss store.Store) {
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, -1, errIdx)
|
||||
|
||||
r1, nErr := ss.Post().Get(o1.Id, false)
|
||||
r1, nErr := ss.Post().Get(o1.Id, false, false, false)
|
||||
require.Nil(t, nErr)
|
||||
ro1a := r1.Posts[o1.Id]
|
||||
|
||||
r2, nErr = ss.Post().Get(o1.Id, false)
|
||||
r2, nErr = ss.Post().Get(o1.Id, false, false, false)
|
||||
require.Nil(t, nErr)
|
||||
ro2a := r2.Posts[o2.Id]
|
||||
|
||||
r3, nErr = ss.Post().Get(o3.Id, false)
|
||||
r3, nErr = ss.Post().Get(o3.Id, false, false, false)
|
||||
require.Nil(t, nErr)
|
||||
ro3a := r3.Posts[o3.Id]
|
||||
|
||||
@@ -2218,11 +2313,11 @@ func testPostStoreOverwriteMultiple(t *testing.T, ss store.Store) {
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, -1, errIdx)
|
||||
|
||||
r4, nErr := ss.Post().Get(o4.Id, false)
|
||||
r4, nErr := ss.Post().Get(o4.Id, false, false, false)
|
||||
require.Nil(t, nErr)
|
||||
ro4a := r4.Posts[o4.Id]
|
||||
|
||||
r5, nErr = ss.Post().Get(o5.Id, false)
|
||||
r5, nErr = ss.Post().Get(o5.Id, false, false, false)
|
||||
require.Nil(t, nErr)
|
||||
ro5a := r5.Posts[o5.Id]
|
||||
|
||||
@@ -2265,19 +2360,19 @@ func testPostStoreOverwrite(t *testing.T, ss store.Store) {
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
r1, err := ss.Post().Get(o1.Id, false)
|
||||
r1, err := ss.Post().Get(o1.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
ro1 := r1.Posts[o1.Id]
|
||||
|
||||
r2, err := ss.Post().Get(o2.Id, false)
|
||||
r2, err := ss.Post().Get(o2.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
ro2 := r2.Posts[o2.Id]
|
||||
|
||||
r3, err := ss.Post().Get(o3.Id, false)
|
||||
r3, err := ss.Post().Get(o3.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
ro3 := r3.Posts[o3.Id]
|
||||
|
||||
r4, err := ss.Post().Get(o4.Id, false)
|
||||
r4, err := ss.Post().Get(o4.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
ro4 := r4.Posts[o4.Id]
|
||||
|
||||
@@ -2302,15 +2397,15 @@ func testPostStoreOverwrite(t *testing.T, ss store.Store) {
|
||||
_, err = ss.Post().Overwrite(o3a)
|
||||
require.Nil(t, err)
|
||||
|
||||
r1, err = ss.Post().Get(o1.Id, false)
|
||||
r1, err = ss.Post().Get(o1.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
ro1a := r1.Posts[o1.Id]
|
||||
|
||||
r2, err = ss.Post().Get(o1.Id, false)
|
||||
r2, err = ss.Post().Get(o1.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
ro2a := r2.Posts[o2.Id]
|
||||
|
||||
r3, err = ss.Post().Get(o3.Id, false)
|
||||
r3, err = ss.Post().Get(o3.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
ro3a := r3.Posts[o3.Id]
|
||||
|
||||
@@ -2326,7 +2421,7 @@ func testPostStoreOverwrite(t *testing.T, ss store.Store) {
|
||||
_, err = ss.Post().Overwrite(o4a)
|
||||
require.Nil(t, err)
|
||||
|
||||
r4, err = ss.Post().Get(o4.Id, false)
|
||||
r4, err = ss.Post().Get(o4.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
ro4a := r4.Posts[o4.Id]
|
||||
@@ -2357,15 +2452,15 @@ func testPostStoreGetPostsByIds(t *testing.T, ss store.Store) {
|
||||
o3, err = ss.Post().Save(o3)
|
||||
require.Nil(t, err)
|
||||
|
||||
r1, err := ss.Post().Get(o1.Id, false)
|
||||
r1, err := ss.Post().Get(o1.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
ro1 := r1.Posts[o1.Id]
|
||||
|
||||
r2, err := ss.Post().Get(o2.Id, false)
|
||||
r2, err := ss.Post().Get(o2.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
ro2 := r2.Posts[o2.Id]
|
||||
|
||||
r3, err := ss.Post().Get(o3.Id, false)
|
||||
r3, err := ss.Post().Get(o3.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
ro3 := r3.Posts[o3.Id]
|
||||
|
||||
@@ -2472,13 +2567,13 @@ func testPostStorePermanentDeleteBatch(t *testing.T, ss store.Store) {
|
||||
_, err = ss.Post().PermanentDeleteBatch(2000, 1000)
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = ss.Post().Get(o1.Id, false)
|
||||
_, err = ss.Post().Get(o1.Id, false, false, false)
|
||||
require.NotNil(t, err, "Should have not found post 1 after purge")
|
||||
|
||||
_, err = ss.Post().Get(o2.Id, false)
|
||||
_, err = ss.Post().Get(o2.Id, false, false, false)
|
||||
require.NotNil(t, err, "Should have not found post 2 after purge")
|
||||
|
||||
_, err = ss.Post().Get(o3.Id, false)
|
||||
_, err = ss.Post().Get(o3.Id, false, false, false)
|
||||
require.Nil(t, err, "Should have not found post 3 after purge")
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ func testReactionSave(t *testing.T, ss store.Store) {
|
||||
assert.Equal(t, saved.EmojiName, reaction1.EmojiName, "should've saved reaction emoji_name and returned it")
|
||||
|
||||
var secondUpdateAt int64
|
||||
postList, err := ss.Post().Get(reaction1.PostId, false)
|
||||
postList, err := ss.Post().Get(reaction1.PostId, false, false, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
assert.True(t, postList.Posts[post.Id].HasReactions, "should've set HasReactions = true on post")
|
||||
@@ -74,7 +74,7 @@ func testReactionSave(t *testing.T, ss store.Store) {
|
||||
_, nErr = ss.Reaction().Save(reaction2)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
postList, err = ss.Post().Get(reaction2.PostId, false)
|
||||
postList, err = ss.Post().Get(reaction2.PostId, false, false, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
assert.NotEqual(t, postList.Posts[post.Id].UpdateAt, secondUpdateAt, "should've marked post as updated even if HasReactions doesn't change")
|
||||
@@ -123,7 +123,7 @@ func testReactionDelete(t *testing.T, ss store.Store) {
|
||||
_, nErr := ss.Reaction().Save(reaction)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
result, err := ss.Post().Get(reaction.PostId, false)
|
||||
result, err := ss.Post().Get(reaction.PostId, false, false, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
firstUpdateAt := result.Posts[post.Id].UpdateAt
|
||||
@@ -136,7 +136,7 @@ func testReactionDelete(t *testing.T, ss store.Store) {
|
||||
|
||||
assert.Empty(t, reactions, "should've deleted reaction")
|
||||
|
||||
postList, err := ss.Post().Get(post.Id, false)
|
||||
postList, err := ss.Post().Get(post.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
assert.False(t, postList.Posts[post.Id].HasReactions, "should've set HasReactions = false on post")
|
||||
@@ -297,15 +297,15 @@ func testReactionDeleteAllWithEmojiName(t *testing.T, ss store.Store) {
|
||||
assert.Empty(t, returned, "should've only removed reactions with emoji name")
|
||||
|
||||
// check that the posts are updated
|
||||
postList, err := ss.Post().Get(post.Id, false)
|
||||
postList, err := ss.Post().Get(post.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
assert.True(t, postList.Posts[post.Id].HasReactions, "post should still have reactions")
|
||||
|
||||
postList, err = ss.Post().Get(post2.Id, false)
|
||||
postList, err = ss.Post().Get(post2.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
assert.True(t, postList.Posts[post2.Id].HasReactions, "post should still have reactions")
|
||||
|
||||
postList, err = ss.Post().Get(post3.Id, false)
|
||||
postList, err = ss.Post().Get(post3.Id, false, false, false)
|
||||
require.Nil(t, err)
|
||||
assert.False(t, postList.Posts[post3.Id].HasReactions, "post shouldn't have reactions any more")
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ func testThreadStorePopulation(t *testing.T, ss store.Store) {
|
||||
|
||||
newPosts, errIdx, err3 := ss.Post().SaveMultiple([]*model.Post{&o2, &o3, &o4})
|
||||
|
||||
olist, _ := ss.Post().Get(otmp.Id, true)
|
||||
olist, _ := ss.Post().Get(otmp.Id, true, false, false)
|
||||
o1 := olist.Posts[olist.Order[0]]
|
||||
|
||||
newPosts = append([]*model.Post{o1}, newPosts...)
|
||||
|
||||
@@ -4444,10 +4444,10 @@ func (s *TimerLayerPostStore) Delete(postId string, time int64, deleteByID strin
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *TimerLayerPostStore) Get(id string, skipFetchThreads bool) (*model.PostList, error) {
|
||||
func (s *TimerLayerPostStore) Get(id string, skipFetchThreads bool, collapsedThreads bool, collapsedThreadsExtended bool) (*model.PostList, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.PostStore.Get(id, skipFetchThreads)
|
||||
result, err := s.PostStore.Get(id, skipFetchThreads, collapsedThreads, collapsedThreadsExtended)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
@@ -4476,10 +4476,10 @@ func (s *TimerLayerPostStore) GetDirectPostParentsForExportAfter(limit int, afte
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerPostStore) GetEtag(channelId string, allowFromCache bool) string {
|
||||
func (s *TimerLayerPostStore) GetEtag(channelId string, allowFromCache bool, collapsedThreads bool) string {
|
||||
start := timemodule.Now()
|
||||
|
||||
result := s.PostStore.GetEtag(channelId, allowFromCache)
|
||||
result := s.PostStore.GetEtag(channelId, allowFromCache, collapsedThreads)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user