Fix the reply count for pinned posts (#14744)

Этот коммит содержится в:
Jesús Espino
2020-06-09 18:42:59 +02:00
коммит произвёл GitHub
родитель cac154e62b
Коммит 9c9bdb8a90
2 изменённых файлов: 42 добавлений и 1 удалений

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

@@ -733,7 +733,7 @@ func (s SqlChannelStore) GetPinnedPosts(channelId string) (*model.PostList, *mod
pl := model.NewPostList()
var posts []*model.Post
if _, err := s.GetReplica().Select(&posts, "SELECT * FROM Posts WHERE IsPinned = true AND ChannelId = :ChannelId AND DeleteAt = 0 ORDER BY CreateAt ASC", map[string]interface{}{"ChannelId": channelId}); err != nil {
if _, err := s.GetReplica().Select(&posts, "SELECT *, (SELECT count(Posts.Id) FROM Posts WHERE Posts.RootId = (CASE WHEN p.RootId = '' THEN p.Id ELSE p.RootId END) AND Posts.DeleteAt = 0) as ReplyCount FROM Posts p WHERE IsPinned = true AND ChannelId = :ChannelId AND DeleteAt = 0 ORDER BY CreateAt ASC", map[string]interface{}{"ChannelId": channelId}); err != nil {
return nil, model.NewAppError("SqlPostStore.GetPinnedPosts", "store.sql_channel.pinned_posts.app_error", nil, err.Error(), http.StatusInternalServerError)
}
for _, post := range posts {

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

@@ -5589,6 +5589,47 @@ func testChannelStoreGetPinnedPosts(t *testing.T, ss store.Store) {
pl, errGet = ss.Channel().GetPinnedPosts(o2.Id)
require.Nil(t, errGet, errGet)
require.Empty(t, pl.Posts, "wasn't supposed to return posts")
t.Run("with correct ReplyCount", func(t *testing.T) {
channelId := model.NewId()
userId := model.NewId()
post1, err := ss.Post().Save(&model.Post{
ChannelId: channelId,
UserId: userId,
Message: "message",
IsPinned: true,
})
require.Nil(t, err)
time.Sleep(time.Millisecond)
post2, err := ss.Post().Save(&model.Post{
ChannelId: channelId,
UserId: userId,
Message: "message",
IsPinned: true,
})
require.Nil(t, err)
time.Sleep(time.Millisecond)
post3, err := ss.Post().Save(&model.Post{
ChannelId: channelId,
UserId: userId,
ParentId: post1.Id,
RootId: post1.Id,
Message: "message",
IsPinned: true,
})
require.Nil(t, err)
time.Sleep(time.Millisecond)
posts, err := ss.Channel().GetPinnedPosts(channelId)
require.Nil(t, err)
require.Len(t, posts.Posts, 3)
require.Equal(t, posts.Posts[post1.Id].ReplyCount, int64(1))
require.Equal(t, posts.Posts[post2.Id].ReplyCount, int64(0))
require.Equal(t, posts.Posts[post3.Id].ReplyCount, int64(1))
})
}
func testChannelStoreGetPinnedPostCount(t *testing.T, ss store.Store) {