@Override public IndexingResult index(DbSession dbSession, Collection<EsQueueDto> items) { if (items.isEmpty()) { return new IndexingResult(); } OneToManyResilientIndexingListener listener = new OneToManyResilientIndexingListener(dbClient, dbSession, items); BulkIndexer bulkIndexer = new BulkIndexer(esClient, INDEX_TYPE_COMPONENT, Size.REGULAR, listener); bulkIndexer.start(); Set<String> branchUuids = items.stream().map(EsQueueDto::getDocId).collect(MoreCollectors.toHashSet(items.size())); Set<String> remaining = new HashSet<>(branchUuids); for (String branchUuid : branchUuids) { // TODO allow scrolling multiple projects at the same time dbClient.componentDao().scrollForIndexing(dbSession, branchUuid, context -> { ComponentDto dto = context.getResultObject(); bulkIndexer.add(newIndexRequest(toDocument(dto))); remaining.remove(dto.projectUuid()); }); } // the remaining uuids reference projects that don't exist in db. They must // be deleted from index. remaining.forEach(projectUuid -> addProjectDeletionToBulkIndexer(bulkIndexer, projectUuid)); return bulkIndexer.stop(); }
/** * @param projectUuid the uuid of the project to analyze, or {@code null} if all content should be indexed.<br/> * <b>Warning:</b> only use {@code null} during startup. */ private void doIndexByProjectUuid(@Nullable String projectUuid, Size bulkSize) { BulkIndexer bulk = new BulkIndexer(esClient, INDEX_TYPE_COMPONENT, bulkSize); bulk.start(); try (DbSession dbSession = dbClient.openSession(false)) { dbClient.componentDao() .scrollForIndexing(dbSession, projectUuid, context -> { ComponentDto dto = context.getResultObject(); bulk.add(newIndexRequest(toDocument(dto))); }); } bulk.stop(); }
private ListAssert<String> assertSelectForIndexing(@Nullable String projectUuid) { OrganizationDto organization = db.organizations().insert(); ComponentDto project = db.components().insertPrivateProject(organization, "U1"); ComponentDto removedProject = db.components().insertPrivateProject(organization, p -> p.setEnabled(false)); ComponentDto module = db.components().insertComponent(newModuleDto("U2", project)); ComponentDto removedModule = db.components().insertComponent(newModuleDto(project).setEnabled(false)); ComponentDto directory = db.components().insertComponent(newDirectory(module, "U3", "src")); ComponentDto removedDirectory = db.components().insertComponent(newDirectory(module, "src2").setEnabled(false)); ComponentDto file = db.components().insertComponent(newFileDto(module, directory, "U4")); ComponentDto removedFile = db.components().insertComponent(newFileDto(module, directory).setEnabled(false)); ComponentDto view = db.components().insertView(organization, "VW1"); db.components().insertComponent(newProjectCopy("COPY8", project, view)); ComponentDto project2 = db.components().insertPrivateProject(organization, "U5"); ComponentDto moduleOnProject2 = db.components().insertComponent(newModuleDto("U6", project2)); List<ComponentDto> components = new ArrayList<>(); underTest.scrollForIndexing(dbSession, projectUuid, context -> components.add(context.getResultObject())); return (ListAssert<String>) assertThat(components).extracting(ComponentDto::uuid); }
@Override public IndexingResult index(DbSession dbSession, Collection<EsQueueDto> items) { if (items.isEmpty()) { return new IndexingResult(); } OneToManyResilientIndexingListener listener = new OneToManyResilientIndexingListener(dbClient, dbSession, items); BulkIndexer bulkIndexer = new BulkIndexer(esClient, INDEX_TYPE_COMPONENT, Size.REGULAR, listener); bulkIndexer.start(); Set<String> branchUuids = items.stream().map(EsQueueDto::getDocId).collect(MoreCollectors.toHashSet(items.size())); Set<String> remaining = new HashSet<>(branchUuids); for (String branchUuid : branchUuids) { // TODO allow scrolling multiple projects at the same time dbClient.componentDao().scrollForIndexing(dbSession, branchUuid, context -> { ComponentDto dto = context.getResultObject(); bulkIndexer.add(newIndexRequest(toDocument(dto))); remaining.remove(dto.projectUuid()); }); } // the remaining uuids reference projects that don't exist in db. They must // be deleted from index. remaining.forEach(projectUuid -> addProjectDeletionToBulkIndexer(bulkIndexer, projectUuid)); return bulkIndexer.stop(); }
/** * @param projectUuid the uuid of the project to analyze, or {@code null} if all content should be indexed.<br/> * <b>Warning:</b> only use {@code null} during startup. */ private void doIndexByProjectUuid(@Nullable String projectUuid, Size bulkSize) { BulkIndexer bulk = new BulkIndexer(esClient, INDEX_TYPE_COMPONENT, bulkSize); bulk.start(); try (DbSession dbSession = dbClient.openSession(false)) { dbClient.componentDao() .scrollForIndexing(dbSession, projectUuid, context -> { ComponentDto dto = context.getResultObject(); bulk.add(newIndexRequest(toDocument(dto))); }); } bulk.stop(); }