]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10430 speed-up DB migration
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 28 May 2018 18:05:52 +0000 (20:05 +0200)
committerSonarTech <sonartech@sonarsource.com>
Mon, 28 May 2018 18:20:45 +0000 (20:20 +0200)
Signed-off-by: Simon Brandhof <simon.brandhof@sonarsource.com>
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v72/PopulateFileSourceLineCount.java

index 756f4d9c66617704bd4725211091ec61e15f80f8..104842085a887bd25848f34f1e03df6841ef24ad 100644 (file)
@@ -47,8 +47,11 @@ public class PopulateFileSourceLineCount extends DataChange {
   protected void execute(Context context) throws SQLException {
     MassUpdate massUpdate = context.prepareMassUpdate();
     massUpdate.select("select distinct project_uuid from file_sources where line_count is null");
-    massUpdate.update("update file_sources set line_count = ? where project_uuid = ?");
-    massUpdate.rowPluralName("file source line counts");
+    massUpdate.update("update file_sources set line_count = ? where project_uuid = ?")
+      // Having transactions involving many rows can be very slow and should be avoided.
+      // A project can have many file_sources, so transaction is committed after each project.
+      .setBatchSize(1);
+    massUpdate.rowPluralName("file sources");
     massUpdate.execute(PopulateFileSourceLineCount::handle);
   }