@Override public IndexingResult index(DbSession dbSession, Collection<EsQueueDto> items) { IndexingResult result = new IndexingResult(); List<BulkIndexer> bulkIndexers = items.stream() .map(EsQueueDto::getDocType) .distinct() .map(IndexType::parse) .filter(indexTypes::contains) .map(indexType -> new BulkIndexer(esClient, indexType, Size.REGULAR, new OneToOneResilientIndexingListener(dbClient, dbSession, items))) .collect(Collectors.toList()); if (bulkIndexers.isEmpty()) { return result; } bulkIndexers.forEach(BulkIndexer::start); PermissionIndexerDao permissionIndexerDao = new PermissionIndexerDao(); Set<String> remainingProjectUuids = items.stream().map(EsQueueDto::getDocId).collect(MoreCollectors.toHashSet()); permissionIndexerDao.selectByUuids(dbClient, dbSession, remainingProjectUuids).forEach(p -> { remainingProjectUuids.remove(p.getProjectUuid()); bulkIndexers.forEach(bi -> bi.add(newIndexRequest(p, bi.getIndexType()))); }); // the remaining references on projects that don't exist in db. They must // be deleted from index. remainingProjectUuids.forEach(projectUuid -> bulkIndexers.forEach(bi -> bi.addDeletion(bi.getIndexType(), projectUuid, projectUuid))); bulkIndexers.forEach(b -> result.add(b.stop())); return result; }
@Override public IndexingResult index(DbSession dbSession, Collection<EsQueueDto> items) { IndexingResult result = new IndexingResult(); List<BulkIndexer> bulkIndexers = items.stream() .map(EsQueueDto::getDocType) .distinct() .map(IndexType::parse) .filter(indexTypes::contains) .map(indexType -> new BulkIndexer(esClient, indexType, Size.REGULAR, new OneToOneResilientIndexingListener(dbClient, dbSession, items))) .collect(Collectors.toList()); if (bulkIndexers.isEmpty()) { return result; } bulkIndexers.forEach(BulkIndexer::start); PermissionIndexerDao permissionIndexerDao = new PermissionIndexerDao(); Set<String> remainingProjectUuids = items.stream().map(EsQueueDto::getDocId).collect(MoreCollectors.toHashSet()); permissionIndexerDao.selectByUuids(dbClient, dbSession, remainingProjectUuids).forEach(p -> { remainingProjectUuids.remove(p.getProjectUuid()); bulkIndexers.forEach(bi -> bi.add(newIndexRequest(p, bi.getIndexType()))); }); // the remaining references on projects that don't exist in db. They must // be deleted from index. remainingProjectUuids.forEach(projectUuid -> bulkIndexers.forEach(bi -> bi.addDeletion(bi.getIndexType(), projectUuid, projectUuid))); bulkIndexers.forEach(b -> result.add(b.stop())); return result; }