From 32b1ea01cfd95dddf0f490f3eca729e1959354d7 Mon Sep 17 00:00:00 2001 From: Ghost_chu Date: Tue, 7 Jan 2025 03:41:32 +0800 Subject: [PATCH] update --- .../module/clientdiscovery/ClientDiscoveryService.java | 10 +++++++++- src/main/resources/application.properties | 1 - 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ghostchu/btn/sparkle/module/clientdiscovery/ClientDiscoveryService.java b/src/main/java/com/ghostchu/btn/sparkle/module/clientdiscovery/ClientDiscoveryService.java index 8f25e1e..52f355a 100644 --- a/src/main/java/com/ghostchu/btn/sparkle/module/clientdiscovery/ClientDiscoveryService.java +++ b/src/main/java/com/ghostchu/btn/sparkle/module/clientdiscovery/ClientDiscoveryService.java @@ -5,10 +5,12 @@ import com.ghostchu.btn.sparkle.util.ByteUtil; import com.ghostchu.btn.sparkle.util.paging.SparklePage; import io.micrometer.core.instrument.MeterRegistry; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.Cacheable; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Propagation; @@ -19,6 +21,7 @@ import java.util.Collection; @Service +@Slf4j public class ClientDiscoveryService { private final ClientDiscoveryRepository clientDiscoveryRepository; @Autowired @@ -29,10 +32,15 @@ public ClientDiscoveryService(ClientDiscoveryRepository clientDiscoveryRepositor } @Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.READ_UNCOMMITTED) + @Async public void handleIdentities(OffsetDateTime timeForFoundAt, OffsetDateTime timeForLastSeenAt, Collection clientIdentities) { meterRegistry.counter("sparkle_client_discovery_processed").increment(); for (ClientIdentity ci : clientIdentities) { - clientDiscoveryRepository.saveIgnoreConflict(ci.hash(), ByteUtil.filterUTF8(ci.getClientName()), ByteUtil.filterUTF8(ci.getPeerId()), timeForFoundAt); + try { + clientDiscoveryRepository.saveIgnoreConflict(ci.hash(), ByteUtil.filterUTF8(ci.getClientName()), ByteUtil.filterUTF8(ci.getPeerId()), timeForFoundAt); + } catch (Exception e) { + log.error("Failed to save client discovery: {}:{}", e.getClass().getName(), e.getMessage()); + } } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 7f55112..afec99f 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -39,7 +39,6 @@ spring.jpa.properties.hibernate.globally_quoted_identifiers_skip_column_definiti spring.jpa.properties.hibernate.session_factory.stateless.enabled=true spring.jpa.properties.hibernate.order_inserts=true spring.jpa.properties.hibernate.jdbc.batch_size=2000 -spring.jpa.properties.hibernate.jdbc.batch_versioned_data=true spring.jpa.properties.hibernate.generate_statistics=false spring.data.redis.host=localhost spring.data.redis.port=6379