public Mono<DeleteResult> deleteRelatedUsersFromAllRelationshipGroups(
            @NotEmpty Set<UserRelationship.@ValidUserRelationshipKey Key> keys,
            @Nullable ClientSession session,
            boolean updateRelationshipGroupsMembersVersion) {
        try {
            Validator.notEmpty(keys, "keys");
            for (UserRelationship.Key key : keys) {
                DataValidator.validRelationshipKey(key);
            }
        } catch (ResponseException e) {
            return Mono.error(e);
        }
        Mono<DeleteResult> deleteMono;
        // fast path
        if (keys.size() == 1) {
            UserRelationship.Key key = keys.iterator()
                    .next();
            deleteMono = userRelationshipGroupMemberRepository
                    .deleteRelatedUsersFromAllRelationshipGroups(key.getOwnerId(),
                            Set.of(key.getRelatedUserId()),
                            session);
        } else {
            // slow path
            Map<Long, List<Long>> ownerIdToRelatedUserIds =
                    CollectionUtil.newMapWithExpectedSize(keys.size());
            for (UserRelationship.Key key : keys) {
                ownerIdToRelatedUserIds
                        .computeIfAbsent(key.getOwnerId(), ignored -> new LinkedList<>())
                        .add(key.getRelatedUserId());
            }
            Set<Map.Entry<Long, List<Long>>> entries = ownerIdToRelatedUserIds.entrySet();
            int size = entries.size();
            if (size == 1) {
                Map.Entry<Long, List<Long>> ownerIdAndRelatedUserIds = entries.iterator()
                        .next();
                deleteMono = userRelationshipGroupMemberRepository
                        .deleteRelatedUsersFromAllRelationshipGroups(ownerIdAndRelatedUserIds
                                .getKey(), ownerIdAndRelatedUserIds.getValue(), session);
            } else {
                List<Mono<DeleteResult>> deleteMonos = new ArrayList<>(size);
                for (Map.Entry<Long, List<Long>> ownerIdAndRelatedUserIds : entries) {
                    deleteMonos.add(userRelationshipGroupMemberRepository
                            .deleteRelatedUsersFromAllRelationshipGroups(ownerIdAndRelatedUserIds
                                    .getKey(), ownerIdAndRelatedUserIds.getValue(), session));
                }
                deleteMono = Flux.merge(deleteMonos)
                        .collect(CollectorUtil.toList(size))
                        .map(OperationResultConvertor::merge);
            }
        }
        if (updateRelationshipGroupsMembersVersion) {
            return deleteMono.flatMap(result -> {
                Set<Long> ownerIds = CollectionUtil.newSetWithExpectedSize(keys.size());
                for (UserRelationship.Key key : keys) {
                    ownerIds.add(key.getOwnerId());
                }
                return userVersionService.updateRelationshipGroupsVersion(ownerIds)
                        .onErrorResume(t -> {
                            LOGGER.error(
                                    "Caught an error while updating the relationship groups version of the owners {} after deleting users from all groups",
                                    ownerIds,
                                    t);
                            return Mono.empty();
                        })
                        .thenReturn(result);
            });
        }
        return deleteMono;
    }
@return true if added a new related user to the relationship group.
@implNote We call this method while upserting a relationship into the owner's relationship
          group in a transaction currently, so we don't check whether the owner has a
          relationship with the related user in this method.
turms-service/src/main/java/im/turms/service/domain/user/service/UserRelationshipGroupService.java