diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-05-04 16:20:50 +0200 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-05-12 11:18:19 +0200 |
commit | 4b655d90490eb074d2e6192709146cb2744c0010 (patch) | |
tree | 1efb48c73cebc54a97e35d7729310e1a03893170 /server | |
parent | fde768cd6f42c74c95755ba2ead666adef2fa082 (diff) | |
download | sonarqube-4b655d90490eb074d2e6192709146cb2744c0010.tar.gz sonarqube-4b655d90490eb074d2e6192709146cb2744c0010.zip |
SONAR-6315 use batch SQL session to insert change log
in MassRegisterQualityProfiles
Diffstat (limited to 'server')
3 files changed, 15 insertions, 14 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/DefinedQProfileInsert.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/DefinedQProfileInsert.java index 0eafd84ad6f..b689a6a70b6 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/DefinedQProfileInsert.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/DefinedQProfileInsert.java @@ -24,5 +24,5 @@ import org.sonar.db.DbSession; import org.sonar.db.organization.OrganizationDto; public interface DefinedQProfileInsert { - void create(DbSession session, DefinedQProfile definedQProfile, OrganizationDto organization, List<ActiveRuleChange> changes); + void create(DbSession session, DbSession batchSession, DefinedQProfile definedQProfile, OrganizationDto organization, List<ActiveRuleChange> changes); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/DefinedQProfileInsertImpl.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/DefinedQProfileInsertImpl.java index e52eda88b06..82ba53a02e4 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/DefinedQProfileInsertImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/DefinedQProfileInsertImpl.java @@ -72,11 +72,10 @@ public class DefinedQProfileInsertImpl implements DefinedQProfileInsert { } @Override - public void create(DbSession session, DefinedQProfile definedQProfile, OrganizationDto organization, List<ActiveRuleChange> changes) { - initRuleRepository(session); + public void create(DbSession session, DbSession batchSession, DefinedQProfile definedQProfile, OrganizationDto organization, List<ActiveRuleChange> changes) { + initRuleRepository(batchSession); - checkArgument(definedQProfile.getParentQProfileName() == null, - "Inheritance of Quality Profiles is not supported yet"); + checkArgument(definedQProfile.getParentQProfileName() == null, "Inheritance of Quality Profiles is not supported yet"); Date now = new Date(system2.now()); QualityProfileDto profileDto = insertQualityProfile(session, definedQProfile, organization, now); @@ -86,7 +85,7 @@ public class DefinedQProfileInsertImpl implements DefinedQProfileInsert { .map(activeRule -> insertActiveRule(session, profileDto, activeRule, now.getTime())) .collect(MoreCollectors.toList()); - localChanges.forEach(change -> dbClient.qProfileChangeDao().insert(session, change.toDto(null))); + localChanges.forEach(change -> dbClient.qProfileChangeDao().insert(batchSession, change.toDto(null))); insertTemplate(session, definedQProfile, organization); diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/MassRegisterQualityProfiles.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/MassRegisterQualityProfiles.java index 6e2a2e76953..6cdd4a91a3b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/MassRegisterQualityProfiles.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/MassRegisterQualityProfiles.java @@ -75,26 +75,27 @@ public class MassRegisterQualityProfiles { return; } - try (DbSession session = dbClient.openSession(false)) { + try (DbSession session = dbClient.openSession(false); + DbSession batchSession = dbClient.openSession(true)) { List<ActiveRuleChange> changes = new ArrayList<>(); definedQProfileRepository.getQProfilesByLanguage() - .forEach((key, value) -> registerPerLanguage(session, value, changes)); + .forEach((key, value) -> registerPerLanguage(session, batchSession, value, changes)); activeRuleIndexer.index(changes); profiler.stopDebug(); } } - private void registerPerLanguage(DbSession session, List<DefinedQProfile> qualityProfiles, List<ActiveRuleChange> changes) { - qualityProfiles.forEach(qp -> registerPerQualityProfile(session, qp, changes)); + private void registerPerLanguage(DbSession session, DbSession batchSession, List<DefinedQProfile> qualityProfiles, List<ActiveRuleChange> changes) { + qualityProfiles.forEach(qp -> registerPerQualityProfile(session, batchSession, qp, changes)); } - private void registerPerQualityProfile(DbSession session, DefinedQProfile qualityProfile, List<ActiveRuleChange> changes) { + private void registerPerQualityProfile(DbSession session, DbSession batchSession, DefinedQProfile qualityProfile, List<ActiveRuleChange> changes) { LOGGER.info("Register profile {}", qualityProfile.getQProfileName()); Profiler profiler = Profiler.create(Loggers.get(getClass())); List<OrganizationDto> organizationDtos; while (!(organizationDtos = getOrganizationsWithoutQP(session, qualityProfile)).isEmpty()) { - organizationDtos.forEach(organization -> registerPerQualityProfileAndOrganization(session, qualityProfile, organization, changes, profiler)); + organizationDtos.forEach(organization -> registerPerQualityProfileAndOrganization(session, batchSession, qualityProfile, organization, changes, profiler)); } } @@ -103,13 +104,14 @@ public class MassRegisterQualityProfiles { qualityProfile.getLoadedTemplateType(), PROCESSED_ORGANIZATIONS_BATCH_SIZE); } - private void registerPerQualityProfileAndOrganization(DbSession session, + private void registerPerQualityProfileAndOrganization(DbSession session, DbSession batchSession, DefinedQProfile definedQProfile, OrganizationDto organization, List<ActiveRuleChange> changes, Profiler profiler) { profiler.start(); - definedQProfileInsert.create(session, definedQProfile, organization, changes); + definedQProfileInsert.create(session, batchSession, definedQProfile, organization, changes); session.commit(); + batchSession.commit(); profiler.stopDebug(format("Register profile %s for organization %s", definedQProfile.getQProfileName(), organization.getKey())); } |