Handle empty remote imports safely

This commit is contained in:
2026-08-19 21:26:26 +08:00
parent ef008ced94
commit 10addc4d52
2 changed files with 6 additions and 7 deletions
@@ -88,11 +88,13 @@ public class PostService {
List<JsonPlaceholderPost> candidates = received.stream()
.filter(this::isImportable)
.toList();
Set<Long> knownSourceIds = postRepository.findAllBySourcePostIdIn(
candidates.stream().map(JsonPlaceholderPost::id).toList())
.stream()
.map(Post::getSourcePostId)
Set<Long> candidateSourceIds = candidates.stream().map(JsonPlaceholderPost::id)
.collect(java.util.stream.Collectors.toSet());
Set<Long> knownSourceIds = candidateSourceIds.isEmpty()
? Set.of()
: postRepository.findAllBySourcePostIdIn(candidateSourceIds).stream()
.map(Post::getSourcePostId)
.collect(java.util.stream.Collectors.toSet());
Set<Long> seenSourceIds = new HashSet<>();
List<Post> newPosts = candidates.stream()
.filter(remotePost -> !knownSourceIds.contains(remotePost.id()))
-3
View File
@@ -9,9 +9,6 @@ spring:
open-in-view: false
hibernate:
ddl-auto: update
cache:
caffeine:
spec: maximumSize=500,expireAfterWrite=10m
mvc:
problemdetails:
enabled: true