[MM-45726] Fix Sentry crash: nil deference in app/post_helpers.go:85 (#20654)
* Avoid adding duplicate post
Этот коммит содержится в:
@@ -784,6 +784,13 @@ func (s *SqlPostStore) Get(ctx context.Context, id string, opts model.GetPostsOp
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, p := range posts {
|
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.AddPost(p)
|
||||||
pl.AddOrder(p.Id)
|
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{})
|
r1, err = ss.Post().Get(context.Background(), o1.Id, opts, o1.UserId, map[string]bool{})
|
||||||
require.NoError(t, err)
|
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)
|
assert.True(t, r1.HasNext)
|
||||||
|
|
||||||
lastPostID = r1.Order[len(r1.Order)-1]
|
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{})
|
r1, err = ss.Post().Get(context.Background(), o1.Id, opts, o1.UserId, map[string]bool{})
|
||||||
require.NoError(t, err)
|
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.LessOrEqual(t, r1.Posts[r1.Order[1]].CreateAt, firstPostCreateAt)
|
||||||
assert.False(t, r1.HasNext)
|
assert.False(t, r1.HasNext)
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user