private static final String SQL_PROJECTS = "SELECT p.organization_uuid, p.uuid, p.kee, p.name, s.uuid, s.created_at, p.tags " +
"FROM projects p " +
"LEFT OUTER JOIN snapshots s ON s.component_uuid=p.uuid AND s.islast=? " +
- "WHERE p.enabled=? AND p.scope=? AND p.qualifier=?";
+ "WHERE p.enabled=? AND p.scope=? AND p.qualifier=? and p.main_branch_project_uuid is null ";
private static final String PROJECT_FILTER = " AND p.uuid=?";
where
p.enabled=${_true}
and p.copy_component_uuid is null
+ and p.main_branch_project_uuid is null
<if test="projectUuid != null">
and p.project_uuid = #{projectUuid,jdbcType=VARCHAR}
</if>
public static ComponentDto newProjectBranch(ComponentDto project, String branchName) {
checkArgument(project.qualifier().equals(Qualifiers.PROJECT));
+ checkArgument(project.getMainBranchProjectUuid() == null);
String uuid = Uuids.createFast();
return new ComponentDto()
.setUuid(uuid)
assertThat(docsById).isEmpty();
}
+ @Test
+ public void non_main_branches_are_not_indexed() {
+ MetricDto metric = insertIntMetric("ncloc");
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
+ SnapshotDto projectAnalysis = dbTester.components().insertProjectAndSnapshot(project);
+ insertMeasure(project, projectAnalysis, metric, 10d);
+
+ ComponentDto branch = ComponentTesting.newProjectBranch(project, "feature/foo");
+ SnapshotDto branchAnalysis = dbTester.components().insertProjectAndSnapshot(branch);
+ insertMeasure(branch, branchAnalysis, metric, 20d);
+
+ Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById();
+
+ assertThat(docsById).hasSize(1).containsOnlyKeys(project.uuid());
+ assertThat(docsById.get(project.uuid()).getMeasures().getNumericMeasures().get(metric.getKey())).isEqualTo(10d);
+ }
+
private Map<String, ProjectMeasures> createResultSetAndReturnDocsById() {
return createResultSetAndReturnDocsById(null);
}
}
@Override
- public void indexOnAnalysis(String projectUuid) {
- doIndexByProjectUuid(projectUuid, Size.REGULAR);
+ public void indexOnAnalysis(String branchUuid) {
+ doIndexByProjectUuid(branchUuid, Size.REGULAR);
}
@Override
case PROJECT_DELETION:
case PROJECT_KEY_UPDATE:
List<EsQueueDto> items = projectUuids.stream()
- .map(projectUuid -> EsQueueDto.create(INDEX_TYPE_COMPONENT.format(), projectUuid, null, projectUuid))
+ .map(branchUuid -> EsQueueDto.create(INDEX_TYPE_COMPONENT.format(), branchUuid, null, branchUuid))
.collect(MoreCollectors.toArrayList(projectUuids.size()));
return dbClient.esQueueDao().insert(dbSession, items);
OneToManyResilientIndexingListener listener = new OneToManyResilientIndexingListener(dbClient, dbSession, items);
BulkIndexer bulkIndexer = new BulkIndexer(esClient, INDEX_TYPE_COMPONENT, Size.REGULAR, listener);
bulkIndexer.start();
- Set<String> projectUuids = items.stream().map(EsQueueDto::getDocId).collect(MoreCollectors.toHashSet(items.size()));
- Set<String> remaining = new HashSet<>(projectUuids);
+ Set<String> branchUuids = items.stream().map(EsQueueDto::getDocId).collect(MoreCollectors.toHashSet(items.size()));
+ Set<String> remaining = new HashSet<>(branchUuids);
- for (String projectUuid : projectUuids) {
+ for (String branchUuid : branchUuids) {
// TODO allow scrolling multiple projects at the same time
- dbClient.componentDao().scrollForIndexing(dbSession, projectUuid, context -> {
+ dbClient.componentDao().scrollForIndexing(dbSession, branchUuid, context -> {
ComponentDto dto = context.getResultObject();
bulkIndexer.add(newIndexRequest(toDocument(dto)));
remaining.remove(dto.projectUuid());
@Override
public void execute() {
- String projectUuid = treeRootHolder.getRoot().getUuid();
+ String branchUuid = treeRootHolder.getRoot().getUuid();
for (ProjectIndexer indexer : indexers) {
LOGGER.debug("Call {}", indexer);
- indexer.indexOnAnalysis(projectUuid);
+ indexer.indexOnAnalysis(branchUuid);
}
}
}
/**
- * This method is called when a project must be (re-)indexed,
- * for example when project is created or when a new analysis
- * is being processed.
- * @param projectUuid non-null UUID of project
+ * This method is called when an analysis must be indexed.
+ *
+ * @param branchUuid non-null UUID of branch in table "projects". It can reference
+ * a non-main branch
*/
- void indexOnAnalysis(String projectUuid);
+ void indexOnAnalysis(String branchUuid);
Collection<EsQueueDto> prepareForRecovery(DbSession dbSession, Collection<String> projectUuids, ProjectIndexer.Cause cause);
}
}
@Override
- public void indexOnAnalysis(String projectUuid) {
- try (IssueIterator issues = issueIteratorFactory.createForProject(projectUuid)) {
+ public void indexOnAnalysis(String branchUuid) {
+ try (IssueIterator issues = issueIteratorFactory.createForProject(branchUuid)) {
doIndex(issues, Size.REGULAR, IndexingListener.NOOP);
}
}
public static final IndexType INDEX_TYPE_PROJECT_MEASURES = new IndexType("projectmeasures", "projectmeasure");
public static final String FIELD_UUID = "uuid";
public static final String FIELD_ORGANIZATION_UUID = "organizationUuid";
+
+ /**
+ * Project key. Only projects (qualifier=TRK)
+ */
public static final String FIELD_KEY = "key";
public static final String FIELD_NAME = "name";
public static final String FIELD_ANALYSED_AT = "analysedAt";
}
@Override
- public void indexOnAnalysis(String projectUuid) {
- doIndex(Size.REGULAR, projectUuid);
+ public void indexOnAnalysis(String branchUuid) {
+ doIndex(Size.REGULAR, branchUuid);
}
@Override
}
}
- // the remaining uuids reference issues that don't exist in db. They must
+ // the remaining uuids reference projects that don't exist in db. They must
// be deleted from index.
projectUuids.forEach(projectUuid -> bulkIndexer.addDeletion(INDEX_TYPE_PROJECT_MEASURES, projectUuid, projectUuid));
private void doIndex(Size size, @Nullable String projectUuid) {
try (DbSession dbSession = dbClient.openSession(false);
- ProjectMeasuresIndexerIterator rowIt = ProjectMeasuresIndexerIterator.create(dbSession, projectUuid)) {
+ ProjectMeasuresIndexerIterator rowIt = ProjectMeasuresIndexerIterator.create(dbSession, projectUuid)) {
BulkIndexer bulkIndexer = createBulkIndexer(size, IndexingListener.NOOP);
bulkIndexer.start();
}
@Override
- public void indexOnAnalysis(String projectUuid) {
+ public void indexOnAnalysis(String branchUuid) {
// nothing to do, permissions don't change during an analysis
}
@Override
public void indexOnStartup(Set<IndexType> uninitializedIndexTypes) {
try (DbSession dbSession = dbClient.openSession(false);
- TestResultSetIterator rowIt = TestResultSetIterator.create(dbClient, dbSession, null)) {
+ TestResultSetIterator rowIt = TestResultSetIterator.create(dbClient, dbSession, null)) {
BulkIndexer bulkIndexer = new BulkIndexer(esClient, INDEX_TYPE_TEST, Size.LARGE);
bulkIndexer.start();
}
@Override
- public void indexOnAnalysis(String projectUuid) {
+ public void indexOnAnalysis(String branchUuid) {
BulkIndexer bulkIndexer = new BulkIndexer(esClient, INDEX_TYPE_TEST, Size.REGULAR);
bulkIndexer.start();
- addProjectDeletionToBulkIndexer(bulkIndexer, projectUuid);
+ addProjectDeletionToBulkIndexer(bulkIndexer, branchUuid);
try (DbSession dbSession = dbClient.openSession(false);
- TestResultSetIterator rowIt = TestResultSetIterator.create(dbClient, dbSession, projectUuid)) {
+ TestResultSetIterator rowIt = TestResultSetIterator.create(dbClient, dbSession, branchUuid)) {
addTestsToBulkIndexer(rowIt, bulkIndexer);
}
bulkIndexer.stop();
assertThatIndexContainsOnly(project1, project2);
}
+ @Test
+ public void indexOnStartup_does_not_index_non_main_branches() {
+ ComponentDto project = db.components().insertPrivateProject();
+ ComponentDto branch = db.components().insertProjectBranch(project, "feature/foo");
+
+ underTest.indexOnStartup(emptySet());
+
+ assertThatIndexContainsOnly(project);
+ }
@Test
public void indexOnAnalysis_indexes_project() {
assertThatComponentHasName(project, "NewName");
}
+ @Test
+ public void indexOnAnalysis_does_not_index_non_main_branches() {
+ ComponentDto project = db.components().insertPrivateProject();
+ ComponentDto branch = db.components().insertProjectBranch(project, "feature/foo");
+
+ underTest.indexOnAnalysis(branch.uuid());
+
+ assertThatIndexHasSize(0);
+ }
+
@Test
public void do_not_update_index_on_project_tag_update() {
ComponentDto project = db.components().insertPrivateProject();
}
@Override
- public void indexOnAnalysis(String projectUuid) {
+ public void indexOnAnalysis(String branchUuid) {
throw new UnsupportedOperationException();
}
}
assertThatIndexContainsOnly(project);
}
+ @Test
+ public void indexOnStartup_ignores_non_main_branches() {
+ ComponentDto project = db.components().insertPrivateProject();
+ ComponentDto branch = db.components().insertProjectBranch(project, "feature/foo");
+
+ underTest.indexOnStartup(emptySet());
+
+ assertThatIndexContainsOnly(project);
+ }
+
@Test
public void indexOnAnalysis_indexes_provisioned_project() {
ComponentDto project1 = db.components().insertPrivateProject();
assertThatIndexContainsOnly(project);
}
+ @Test
+ public void non_main_branches_are_not_indexed_during_analysis() {
+ ComponentDto project = db.components().insertPrivateProject();
+ ComponentDto branch = db.components().insertProjectBranch(project, "feature/foo");
+
+ underTest.indexOnAnalysis(branch.uuid());
+
+ assertThat(es.countDocuments(INDEX_TYPE_PROJECT_MEASURES)).isEqualTo(0);
+ }
+
private IndexingResult indexProject(ComponentDto project, ProjectIndexer.Cause cause) {
DbSession dbSession = db.getSession();
Collection<EsQueueDto> items = underTest.prepareForRecovery(dbSession, singletonList(project.uuid()), cause);
}
@Override
- public void indexOnAnalysis(String projectUuid) {
- addToIndex(projectUuid, "bar");
- addToIndex(projectUuid, "baz");
+ public void indexOnAnalysis(String branchUuid) {
+ addToIndex(branchUuid, "bar");
+ addToIndex(branchUuid, "baz");
}
@Override