]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8798 don't store _id in document bodies anymore
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 13 Jul 2017 15:43:22 +0000 (17:43 +0200)
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>
Wed, 9 Aug 2017 13:09:54 +0000 (15:09 +0200)
* don't store uuid in _id for projectmeasures.projectmeasure
* don't store uuid in _id field for components.component
* don't store id in field _id for Rules.activeRule

server/sonar-server/src/main/java/org/sonar/server/component/index/ComponentDoc.java
server/sonar-server/src/main/java/org/sonar/server/component/index/ComponentIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/measure/index/ProjectMeasuresDoc.java
server/sonar-server/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java
server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java

index 6a02825ba0ef0b3fad7ff896321a5f4edd3eca4a..a785c575d07f6164e479c589754c198859a88228 100644 (file)
@@ -22,15 +22,21 @@ package org.sonar.server.component.index;
 import java.util.HashMap;
 import org.sonar.server.es.BaseDoc;
 
+import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_KEY;
+import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_NAME;
+import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_PROJECT_UUID;
+import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_QUALIFIER;
+import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_UUID;
+
 public class ComponentDoc extends BaseDoc {
 
   public ComponentDoc() {
-    super(new HashMap<>(5));
+    super(new HashMap<>(6));
   }
 
   @Override
   public String getId() {
-    return getField("_id");
+    return getField(FIELD_UUID);
   }
 
   @Override
@@ -44,43 +50,43 @@ public class ComponentDoc extends BaseDoc {
   }
 
   public ComponentDoc setId(String s) {
-    setField("_id", s);
+    setField(FIELD_UUID, s);
     return this;
   }
 
   public String getProjectUuid() {
-    return getField(ComponentIndexDefinition.FIELD_PROJECT_UUID);
+    return getField(FIELD_PROJECT_UUID);
   }
 
   public ComponentDoc setProjectUuid(String s) {
-    setField(ComponentIndexDefinition.FIELD_PROJECT_UUID, s);
+    setField(FIELD_PROJECT_UUID, s);
     return this;
   }
 
   public String getKey() {
-    return getField(ComponentIndexDefinition.FIELD_KEY);
+    return getField(FIELD_KEY);
   }
 
   public ComponentDoc setKey(String s) {
-    setField(ComponentIndexDefinition.FIELD_KEY, s);
+    setField(FIELD_KEY, s);
     return this;
   }
 
   public String getName() {
-    return getField(ComponentIndexDefinition.FIELD_NAME);
+    return getField(FIELD_NAME);
   }
 
   public ComponentDoc setName(String s) {
-    setField(ComponentIndexDefinition.FIELD_NAME, s);
+    setField(FIELD_NAME, s);
     return this;
   }
 
   public String getQualifier() {
-    return getField(ComponentIndexDefinition.FIELD_QUALIFIER);
+    return getField(FIELD_QUALIFIER);
   }
 
   public ComponentDoc setQualifier(String s) {
-    setField(ComponentIndexDefinition.FIELD_QUALIFIER, s);
+    setField(FIELD_QUALIFIER, s);
     return this;
   }
 }
index 686577a86f09b2e340248c8eb743b26aed6c5112..5a77c847914bf00e87281e7ca116210017927470 100644 (file)
@@ -33,6 +33,7 @@ import static org.sonar.server.es.DefaultIndexSettingsElement.SORTABLE_ANALYZER;
 public class ComponentIndexDefinition implements IndexDefinition {
 
   public static final IndexType INDEX_TYPE_COMPONENT = new IndexType("components", "component");
+  public static final String FIELD_UUID = "uuid";
   public static final String FIELD_PROJECT_UUID = "project_uuid";
   public static final String FIELD_KEY = "key";
   public static final String FIELD_NAME = "name";
@@ -57,7 +58,8 @@ public class ComponentIndexDefinition implements IndexDefinition {
     NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_COMPONENT.getType())
       .requireProjectAuthorization();
 
-    mapping.keywordFieldBuilder(FIELD_PROJECT_UUID).build();
+    mapping.keywordFieldBuilder(FIELD_UUID).disableNorms().build();
+    mapping.keywordFieldBuilder(FIELD_PROJECT_UUID).disableNorms().build();
     mapping.keywordFieldBuilder(FIELD_KEY).addSubFields(SORTABLE_ANALYZER).build();
     mapping.keywordFieldBuilder(FIELD_NAME)
       .termVectorWithPositionOffsets()
index c1738c3dd08aaf22cda3a0a461f7f023e47f5583..1d4966d755b6209da255b21ee23af41ac4d0f65d 100644 (file)
@@ -43,18 +43,19 @@ import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIEL
 import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_ORGANIZATION_UUID;
 import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_QUALITY_GATE_STATUS;
 import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_TAGS;
+import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_UUID;
 
 public class ProjectMeasuresDoc extends BaseDoc {
 
   public static final Map<String, Integer> QUALITY_GATE_STATUS = ImmutableMap.of(OK.name(), 1, WARN.name(), 2, ERROR.name(), 3);
 
   public ProjectMeasuresDoc() {
-    super(new HashMap<>(7));
+    super(new HashMap<>(8));
   }
 
   @Override
   public String getId() {
-    return getField("_id");
+    return getField(FIELD_UUID);
   }
 
   @Override
@@ -68,7 +69,7 @@ public class ProjectMeasuresDoc extends BaseDoc {
   }
 
   public ProjectMeasuresDoc setId(String s) {
-    setField("_id", s);
+    setField(FIELD_UUID, s);
     return this;
   }
 
index 9e7881ebd68e00b2ade00b82712f448f3c527d82..d6865ac1aa6bfcd814fe1c24ff72fc0b35e38551 100644 (file)
@@ -30,6 +30,7 @@ import static org.sonar.server.es.DefaultIndexSettingsElement.SORTABLE_ANALYZER;
 public class ProjectMeasuresIndexDefinition implements IndexDefinition {
 
   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";
   public static final String FIELD_KEY = "key";
   public static final String FIELD_NAME = "name";
@@ -56,7 +57,8 @@ public class ProjectMeasuresIndexDefinition implements IndexDefinition {
     NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_PROJECT_MEASURES.getType())
       .requireProjectAuthorization();
 
-    mapping.keywordFieldBuilder(FIELD_ORGANIZATION_UUID).build();
+    mapping.keywordFieldBuilder(FIELD_UUID).disableNorms().build();
+    mapping.keywordFieldBuilder(FIELD_ORGANIZATION_UUID).disableNorms().build();
     mapping.keywordFieldBuilder(FIELD_KEY).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
     mapping.keywordFieldBuilder(FIELD_NAME).addSubFields(SORTABLE_ANALYZER, SEARCH_GRAMS_ANALYZER).build();
     mapping.keywordFieldBuilder(FIELD_QUALITY_GATE_STATUS).build();
index 4eddf1685b497fd89960db01c4e067315d070e09..11efca1ccb3fa764bf77bca1173bcac7ce632083 100644 (file)
@@ -27,6 +27,7 @@ import org.sonar.server.es.BaseDoc;
 import org.sonar.server.qualityprofile.ActiveRule;
 
 import static org.apache.commons.lang.StringUtils.containsIgnoreCase;
+import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_ID;
 import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_INHERITANCE;
 import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_PROFILE_UUID;
 import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_REPOSITORY;
@@ -35,9 +36,9 @@ import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_
 
 public class ActiveRuleDoc extends BaseDoc {
 
-  public ActiveRuleDoc(String id) {
-    super(Maps.newHashMapWithExpectedSize(9));
-    setField("_id", id);
+  public ActiveRuleDoc(long id) {
+    super(Maps.newHashMapWithExpectedSize(10));
+    setField(FIELD_ACTIVE_RULE_ID, String.valueOf(id));
   }
 
   public ActiveRuleDoc(Map<String,Object> source) {
@@ -46,7 +47,7 @@ public class ActiveRuleDoc extends BaseDoc {
 
   @Override
   public String getId() {
-    return getField("_id");
+    return getField(FIELD_ACTIVE_RULE_ID);
   }
 
   @Override
index 1a4610573a525b9b878d749a63bbe182cafada27..0061346194e21b0d581a7cd728481b96514af9d8 100644 (file)
@@ -207,7 +207,7 @@ public class ActiveRuleIndexer implements ResilientIndexer {
   }
 
   private static IndexRequest newIndexRequest(IndexedActiveRuleDto dto) {
-    ActiveRuleDoc doc = new ActiveRuleDoc(String.valueOf(dto.getId()));
+    ActiveRuleDoc doc = new ActiveRuleDoc(dto.getId());
     doc.setRuleProfileUuid(dto.getRuleProfileUuid());
     doc.setSeverity(SeverityUtil.getSeverityFromOrdinal(dto.getSeverity()));
     doc.setRuleKey(RuleKey.of(dto.getRepository(), dto.getKey()));
index 4051e8a9ea0907845bcc2b5c5291682e51c9ab0a..ee85ac972ce7ca8d304db47231cc88b20879ce16 100644 (file)
@@ -72,6 +72,7 @@ public class RuleIndexDefinition implements IndexDefinition {
 
   // Active rule fields
   public static final IndexType INDEX_TYPE_ACTIVE_RULE = new IndexType(INDEX, "activeRule");
+  public static final String FIELD_ACTIVE_RULE_ID = "id";
   public static final String FIELD_ACTIVE_RULE_REPOSITORY = "repo";
   public static final String FIELD_ACTIVE_RULE_INHERITANCE = "inheritance";
   public static final String FIELD_ACTIVE_RULE_PROFILE_UUID = "ruleProfile";
@@ -114,6 +115,7 @@ public class RuleIndexDefinition implements IndexDefinition {
     activeRuleMapping.setEnableSource(enableSource);
     activeRuleMapping.setAttribute("_parent", ImmutableMap.of("type", INDEX_TYPE_RULE.getType()));
 
+    activeRuleMapping.keywordFieldBuilder(FIELD_ACTIVE_RULE_ID).disableNorms().build();
     activeRuleMapping.keywordFieldBuilder(FIELD_ACTIVE_RULE_RULE_KEY).addSubFields(SORTABLE_ANALYZER).build();
     activeRuleMapping.keywordFieldBuilder(FIELD_ACTIVE_RULE_REPOSITORY).build();
     activeRuleMapping.keywordFieldBuilder(FIELD_ACTIVE_RULE_PROFILE_UUID).disableNorms().build();