From 3629010a96b4aa29ffbbfaab73c09a801d875957 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 27 Dec 2022 13:57:34 +0300 Subject: handle `addFollower` duplicates --- src/main/java/com/juick/service/ActivityPubService.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/com/juick/service/ActivityPubService.java b/src/main/java/com/juick/service/ActivityPubService.java index 1bf1b5d4..c45b0c13 100644 --- a/src/main/java/com/juick/service/ActivityPubService.java +++ b/src/main/java/com/juick/service/ActivityPubService.java @@ -20,6 +20,7 @@ package com.juick.service; import com.juick.model.User; import com.juick.model.AnonymousUser; import org.springframework.beans.factory.annotation.Value; +import org.springframework.dao.DuplicateKeyException; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.util.UriComponents; @@ -58,8 +59,12 @@ public class ActivityPubService extends BaseJdbcService implements SocialService @Transactional @Override public void addFollower(User user, String acct) { - getJdbcTemplate().update("INSERT INTO followers(user_id, acct) " + - "VALUES(?, ?)", user.getUid(), acct); + try { + getJdbcTemplate().update("INSERT INTO followers(user_id, acct) " + + "VALUES(?, ?)", user.getUid(), acct); + } catch (DuplicateKeyException e) { + // ignore + } } @Transactional -- cgit v1.2.3