if (!components.isEmpty()) {
List<Boolean> result = new LinkedList<>();
return executeLargeInputs(components, input -> {
- boolean groupNeedIssueSync = mapper(session).doAnyOfComponentsNeedIssueSync(components) > 0;
+ boolean groupNeedIssueSync = mapper(session).doAnyOfComponentsNeedIssueSync(input) > 0;
result.add(groupNeedIssueSync);
return result;
}).stream()
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
return Optional.ofNullable(mapper(dbSession).selectByAlmIdAndAlmRepositoryId(almId, almRepositoryId));
}
+ public boolean existAnyOfComponentsWithQualifiers(DbSession session, Collection<String> componentKeys, Set<String> qualifiers) {
+ if (!componentKeys.isEmpty()) {
+ List<Boolean> result = new LinkedList<>();
+ return executeLargeInputs(componentKeys, input -> {
+ boolean groupNeedIssueSync = mapper(session).checkIfAnyOfComponentsWithQualifiers(input, qualifiers) > 0;
+ result.add(groupNeedIssueSync);
+ return result;
+ }).stream().anyMatch(b -> b);
+ }
+ return false;
+ }
+
}
List<ProjectNclocDistributionDto> selectPrivateProjectsWithNcloc(@Param("organizationUuid") String organizationUuid);
List<ComponentWithModuleUuidDto> selectEnabledComponentsWithModuleUuidFromProjectKey(String projectKey);
+
+ short checkIfAnyOfComponentsWithQualifiers(@Param("componentKeys") Collection<String> componentKeys, @Param("qualifiers") Set<String> qualifiers);
}
where
m.name = 'ncloc'
and b.key_type = 'BRANCH'
- and b.branch_type = 'BRANCH'
- and p.enabled = ${_true}
- and p.private = ${_true}
- and p.scope = 'PRJ'
- and p.qualifier = 'TRK'
- and p.copy_component_uuid is null
- and p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
+ and b.branch_type = 'BRANCH'
+ and p.enabled = ${_true}
+ and p.private = ${_true}
+ and p.scope = 'PRJ'
+ and p.qualifier = 'TRK'
+ and p.copy_component_uuid is null
+ and p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
group by p.kee, p.name
order by ncloc desc
</select>
+
+ <select id="checkIfAnyOfComponentsWithQualifiers" resultType="short">
+ select
+ case when exists
+ (
+ select c.uuid from components c
+ where c.kee in
+ <foreach collection="componentKeys" open="(" close=")" item="componentKey" separator=",">
+ #{componentKey,jdbcType=VARCHAR}
+ </foreach>
+ and c.scope = 'PRJ'
+ and c.qualifier in
+ <foreach collection="qualifiers" open="(" close=")" item="qualifier" separator=",">
+ #{qualifier,jdbcType=VARCHAR}
+ </foreach>
+ )
+ then 1
+ else 0
+ end
+ </select>
</mapper>
import static com.google.common.collect.ImmutableSet.of;
import static com.google.common.collect.Sets.newHashSet;
import static java.util.Arrays.asList;
+import static java.util.Collections.emptyList;
import static java.util.Collections.emptySet;
import static java.util.Collections.singleton;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.tuple;
import static org.sonar.api.resources.Qualifiers.APP;
import static org.sonar.api.resources.Qualifiers.PROJECT;
+import static org.sonar.api.resources.Qualifiers.SUBVIEW;
+import static org.sonar.api.resources.Qualifiers.VIEW;
import static org.sonar.api.utils.DateUtils.parseDate;
import static org.sonar.db.component.BranchType.BRANCH;
import static org.sonar.db.component.BranchType.PULL_REQUEST;
+import static org.sonar.db.component.ComponentTesting.newApplication;
import static org.sonar.db.component.ComponentTesting.newBranchDto;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
assertThat(result).extracting(ProjectNclocDistributionDto::getNcloc).containsExactly(30L, 10L);
}
+ @Test
+ public void existAnyOfComponentsWithQualifiers() {
+ ComponentDto projectDto = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization()));
+
+ ComponentDto view = db.components().insertComponent(newView(db.getDefaultOrganization()));
+ ComponentDto subview = db.components().insertComponent(newSubView(view));
+
+ ComponentDto app = db.components().insertComponent(newApplication(db.getDefaultOrganization()));
+
+ assertThat(underTest.existAnyOfComponentsWithQualifiers(db.getSession(), emptyList(), newHashSet(APP, VIEW, SUBVIEW))).isFalse();
+ assertThat(underTest.existAnyOfComponentsWithQualifiers(db.getSession(), singletonList("not-existing-component"), newHashSet(APP, VIEW, SUBVIEW))).isFalse();
+ assertThat(underTest.existAnyOfComponentsWithQualifiers(db.getSession(), singletonList(projectDto.getKey()), newHashSet(APP, VIEW, SUBVIEW))).isFalse();
+
+ assertThat(underTest.existAnyOfComponentsWithQualifiers(db.getSession(), singletonList(projectDto.getKey()), newHashSet(PROJECT))).isTrue();
+
+ assertThat(underTest.existAnyOfComponentsWithQualifiers(db.getSession(), singletonList(view.getKey()), newHashSet(APP, VIEW, SUBVIEW))).isTrue();
+ assertThat(underTest.existAnyOfComponentsWithQualifiers(db.getSession(), singletonList(subview.getKey()), newHashSet(APP, VIEW, SUBVIEW))).isTrue();
+ assertThat(underTest.existAnyOfComponentsWithQualifiers(db.getSession(), singletonList(app.getKey()), newHashSet(APP, VIEW, SUBVIEW))).isTrue();
+
+ assertThat(underTest.existAnyOfComponentsWithQualifiers(db.getSession(), newHashSet(projectDto.getKey(), view.getKey()), newHashSet(APP, VIEW, SUBVIEW))).isTrue();
+ }
+
private boolean privateFlagOfUuid(String uuid) {
return underTest.selectByUuid(db.getSession(), uuid).get().isPrivate();
}
*/
package org.sonar.server.issue.index;
+import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import java.util.Collection;
import java.util.Collections;
import org.sonar.db.DbSession;
import org.sonar.server.es.EsIndexSyncInProgressException;
+import static org.sonar.api.resources.Qualifiers.APP;
+import static org.sonar.api.resources.Qualifiers.SUBVIEW;
+import static org.sonar.api.resources.Qualifiers.VIEW;
+
public class IssueIndexSyncProgressChecker {
+ private static final ImmutableSet<String> APP_VIEW_OR_SUBVIEW = ImmutableSet.<String>builder().add(VIEW, SUBVIEW, APP).build();
private final DbClient dbClient;
public IssueIndexSyncProgressChecker(DbClient dbClient) {
}
public void checkIfAnyComponentsNeedIssueSync(DbSession dbSession, List<String> componentKeys) {
- boolean needIssueSync = dbClient.branchDao().doAnyOfComponentsNeedIssueSync(dbSession, componentKeys);
+ boolean isAppOrViewOrSubview = dbClient.componentDao().existAnyOfComponentsWithQualifiers(dbSession, componentKeys, APP_VIEW_OR_SUBVIEW);
+ boolean needIssueSync;
+ if (isAppOrViewOrSubview) {
+ needIssueSync = dbClient.branchDao().hasAnyBranchWhereNeedIssueSync(dbSession, true);
+ } else {
+ needIssueSync = dbClient.branchDao().doAnyOfComponentsNeedIssueSync(dbSession, componentKeys);
+ }
if (needIssueSync) {
throw new EsIndexSyncInProgressException(IssueIndexDefinition.TYPE_ISSUE.getMainType(),
"Results are temporarily unavailable. Indexing of issues is in progress.");
import org.sonar.db.project.ProjectDto;
import org.sonar.server.es.EsIndexSyncInProgressException;
-import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.sonar.db.ce.CeActivityDto.Status.FAILED;
}
@Test
- public void checkIfAnyComponentsIssueSyncInProgress_throws_exception_if_all_components_have_need_issue_sync_TRUE() {
+ public void checkIfAnyComponentsNeedIssueSync_throws_exception_if_all_components_have_need_issue_sync_TRUE() {
ProjectDto projectDto1 = insertProjectWithBranches(true, 0);
ProjectDto projectDto2 = insertProjectWithBranches(true, 0);
DbSession session = db.getSession();
}
@Test
- public void checkIfAnyComponentsIssueSyncInProgress_does_not_throw_exception_if_all_components_have_need_issue_sync_FALSE() {
+ public void checkIfAnyComponentsNeedIssueSync_does_not_throw_exception_if_all_components_have_need_issue_sync_FALSE() {
underTest.checkIfAnyComponentsNeedIssueSync(db.getSession(), Collections.emptyList());
ProjectDto projectDto1 = insertProjectWithBranches(false, 0);
ProjectDto projectDto2 = insertProjectWithBranches(false, 0);
}
@Test
- public void checkIfAnyComponentsIssueSyncInProgress_throws_exception_if_at_least_one_component_has_need_issue_sync_TRUE() {
+ public void checkIfAnyComponentsNeedIssueSync_throws_exception_if_at_least_one_component_has_need_issue_sync_TRUE() {
ProjectDto projectDto1 = insertProjectWithBranches(false, 0);
ProjectDto projectDto2 = insertProjectWithBranches(true, 0);
}
@Test
- public void checkIfAnyComponentsIssueSyncInProgress_single_component() {
+ public void checkIfComponentNeedIssueSync_single_component() {
ProjectDto projectDto1 = insertProjectWithBranches(true, 0);
ProjectDto projectDto2 = insertProjectWithBranches(false, 0);
DbSession session = db.getSession();
- List<String> projectKey1 = singletonList(projectDto2.getKey());
// do nothing when need issue sync false
- underTest.checkIfAnyComponentsNeedIssueSync(session, projectKey1);
+ underTest.checkIfComponentNeedIssueSync(session, projectDto2.getKey());
- List<String> projectKey2 = singletonList(projectDto1.getKey());
// throws if flag set to TRUE
- assertThatThrownBy(() -> underTest.checkIfAnyComponentsNeedIssueSync(session,
- projectKey2))
+ assertThatThrownBy(() -> underTest.checkIfComponentNeedIssueSync(session,
+ projectDto1.getKey()))
.isInstanceOf(EsIndexSyncInProgressException.class)
.hasFieldOrPropertyWithValue("httpCode", 503)
.hasMessage("Results are temporarily unavailable. Indexing of issues is in progress.");