use of org.sonar.db.measure.ProjectMeasuresIndexerIterator in project sonarqube by SonarSource.
the class ProjectMeasuresIndexer method index.
@Override
public IndexingResult index(DbSession dbSession, Collection<EsQueueDto> items) {
if (items.isEmpty()) {
return new IndexingResult();
}
OneToOneResilientIndexingListener listener = new OneToOneResilientIndexingListener(dbClient, dbSession, items);
BulkIndexer bulkIndexer = createBulkIndexer(Size.REGULAR, listener);
bulkIndexer.start();
List<String> projectUuids = items.stream().map(EsQueueDto::getDocId).collect(MoreCollectors.toArrayList(items.size()));
Iterator<String> it = projectUuids.iterator();
while (it.hasNext()) {
String projectUuid = it.next();
try (ProjectMeasuresIndexerIterator rowIt = ProjectMeasuresIndexerIterator.create(dbSession, projectUuid)) {
while (rowIt.hasNext()) {
bulkIndexer.add(toProjectMeasuresDoc(rowIt.next()).toIndexRequest());
it.remove();
}
}
}
// the remaining uuids reference projects that don't exist in db. They must be deleted from index.
projectUuids.forEach(projectUuid -> bulkIndexer.addDeletion(TYPE_PROJECT_MEASURES, projectUuid, AuthorizationDoc.idOf(projectUuid)));
return bulkIndexer.stop();
}
use of org.sonar.db.measure.ProjectMeasuresIndexerIterator in project sonarqube by SonarSource.
the class ProjectMeasuresIndexer method doIndex.
private void doIndex(Size size, @Nullable String projectUuid) {
try (DbSession dbSession = dbClient.openSession(false);
ProjectMeasuresIndexerIterator rowIt = ProjectMeasuresIndexerIterator.create(dbSession, projectUuid)) {
BulkIndexer bulkIndexer = createBulkIndexer(size, IndexingListener.FAIL_ON_ERROR);
bulkIndexer.start();
while (rowIt.hasNext()) {
ProjectMeasures doc = rowIt.next();
bulkIndexer.add(toProjectMeasuresDoc(doc).toIndexRequest());
}
bulkIndexer.stop();
}
}
Aggregations