mirror of https://github.com/usememos/memos.git
refactor(api): remove redundant UID existence check in CreateMemo
The explicit check for existing memo UIDs before insertion is redundant because: - Database has UNIQUE constraint on uid column - The check creates a race condition window - Database constraint is the actual enforcement mechanism Simplified the code to rely on the database constraint. If a duplicate UID is provided, the CreateMemo store call will fail with a constraint violation error.
This commit is contained in:
parent
ce835ca145
commit
94483ea2a4
|
|
@ -33,15 +33,6 @@ func (s *APIV1Service) CreateMemo(ctx context.Context, request *v1pb.CreateMemoR
|
|||
memoUID := strings.TrimSpace(request.MemoId)
|
||||
if memoUID == "" {
|
||||
memoUID = shortuuid.New()
|
||||
} else {
|
||||
// Check if a memo with this UID already exists
|
||||
existingMemo, err := s.Store.GetMemo(ctx, &store.FindMemo{UID: &memoUID})
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to check memo existence")
|
||||
}
|
||||
if existingMemo != nil {
|
||||
return nil, status.Errorf(codes.AlreadyExists, "memo with ID %q already exists", memoUID)
|
||||
}
|
||||
}
|
||||
|
||||
create := &store.Memo{
|
||||
|
|
|
|||
Loading…
Reference in New Issue