Handle empty remote imports safely
This commit is contained in:
@@ -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()))
|
||||
|
||||
@@ -9,9 +9,6 @@ spring:
|
||||
open-in-view: false
|
||||
hibernate:
|
||||
ddl-auto: update
|
||||
cache:
|
||||
caffeine:
|
||||
spec: maximumSize=500,expireAfterWrite=10m
|
||||
mvc:
|
||||
problemdetails:
|
||||
enabled: true
|
||||
|
||||
Reference in New Issue
Block a user