diff --git a/store/sqlstore/post_store.go b/store/sqlstore/post_store.go index 044ee6ca27..3659708401 100644 --- a/store/sqlstore/post_store.go +++ b/store/sqlstore/post_store.go @@ -784,6 +784,13 @@ func (s *SqlPostStore) Get(ctx context.Context, id string, opts model.GetPostsOp } for _, p := range posts { + if p.Id == id { + // Based on the conditions above such as sq.Or{ sq.Eq{"p.Id": rootId}, sq.Eq{"p.RootId": rootId}, } + // posts may contain the "id" post which has already been fetched and added in the "pl" + // So, skip the "id" to avoid duplicate entry of the post + continue + } + pl.AddPost(p) pl.AddOrder(p.Id) } diff --git a/store/storetest/post_store.go b/store/storetest/post_store.go index 2489847905..63965897a4 100644 --- a/store/storetest/post_store.go +++ b/store/storetest/post_store.go @@ -643,7 +643,7 @@ func testPostStoreGetForThread(t *testing.T, ss store.Store) { } r1, err = ss.Post().Get(context.Background(), o1.Id, opts, o1.UserId, map[string]bool{}) require.NoError(t, err) - assert.Len(t, r1.Order, 3) // including the root post + assert.Len(t, r1.Order, 2) // including the root post assert.True(t, r1.HasNext) lastPostID = r1.Order[len(r1.Order)-1] @@ -675,7 +675,7 @@ func testPostStoreGetForThread(t *testing.T, ss store.Store) { } r1, err = ss.Post().Get(context.Background(), o1.Id, opts, o1.UserId, map[string]bool{}) require.NoError(t, err) - assert.Len(t, r1.Order, 3) // including the root post + assert.Len(t, r1.Order, 2) // including the root post assert.LessOrEqual(t, r1.Posts[r1.Order[1]].CreateAt, firstPostCreateAt) assert.False(t, r1.HasNext)