fix: duplicated/reflexive relation in v2 api. (#2750)

This commit is contained in:
Hanqin Guan 2024-01-13 07:21:19 +08:00 committed by GitHub
parent 81942b3b98
commit 16e68fbfff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,6 +21,15 @@ func (s *APIV2Service) SetMemoRelations(ctx context.Context, request *apiv2pb.Se
}
for _, relation := range request.Relations {
// Ignore reflexive relations.
if request.Id == relation.RelatedMemoId {
continue
}
// Ignore comment relations as there's no need to update a comment's relation.
// Inserting/Deleting a comment is handled elsewhere.
if relation.Type == apiv2pb.MemoRelation_COMMENT {
continue
}
if _, err := s.Store.UpsertMemoRelation(ctx, &store.MemoRelation{
MemoID: request.Id,
RelatedMemoID: relation.RelatedMemoId,