[MM-45726] Fix Sentry crash: nil deference in app/post_helpers.go:85 (#20654)

* Avoid adding duplicate post
Этот коммит содержится в:
Vishal
2022-08-02 12:10:26 +05:30
коммит произвёл GitHub
родитель 8444c45959
Коммит fa768e0fa7
2 изменённых файлов: 9 добавлений и 2 удалений

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

@@ -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)
}

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

@@ -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)