From 16e68fbfff0623334e273450db1d3cd7c24ea294 Mon Sep 17 00:00:00 2001 From: Hanqin Guan <53598282+harveyghq@users.noreply.github.com> Date: Sat, 13 Jan 2024 07:21:19 +0800 Subject: [PATCH] fix: duplicated/reflexive relation in v2 api. (#2750) --- api/v2/memo_relation_service.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/api/v2/memo_relation_service.go b/api/v2/memo_relation_service.go index 0f3fa6c2..3c20e43f 100644 --- a/api/v2/memo_relation_service.go +++ b/api/v2/memo_relation_service.go @@ -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,