dev #1
@@ -11,7 +11,10 @@ import ru.no_copy.monitoring.searcher.SearchImageService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@@ -42,10 +45,22 @@ public class MonitoringService {
|
||||
imageService.getAllImagesWithoutPagination(searchResponse,
|
||||
monitoring.getSearchType(),
|
||||
monitoring.getFileId());
|
||||
log.info("Images count: {}", images.size());
|
||||
|
||||
log.info("Images count before filter: {}", images.size());
|
||||
|
||||
images = images.stream()
|
||||
.filter(distinctByKey(SearchResponse.ImageResult::getUrl))
|
||||
.toList();
|
||||
|
||||
log.info("Images count after filter: {}", images.size());
|
||||
|
||||
for (SearchResponse.ImageResult imageResult: images) {
|
||||
kafkaTemplate.send("monitoring-results", imageResult);
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> java.util.function.Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
|
||||
Set<Object> seen = ConcurrentHashMap.newKeySet();
|
||||
return t -> seen.add(keyExtractor.apply(t));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user