]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-15335 - Avoid returning duplicates in Export Findings
authorBelen Pruvost <belen.pruvost@sonarsource.com>
Fri, 10 Sep 2021 13:56:06 +0000 (15:56 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 14 Sep 2021 20:03:24 +0000 (20:03 +0000)
server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java

index ac729b3bb040ca6cad608a7b877f0c741b369d28..52ef7a4f10c167c6a5e4e5d6d608d380f98b527d 100644 (file)
@@ -58,6 +58,10 @@ public class IssueDao implements Dao {
     return executeLargeInputs(keys, mapper(session)::selectByKeys);
   }
 
+  public Set<String> selectIssueKeysByComponentUuid(DbSession session, String componentUuid) {
+    return mapper(session).selectIssueKeysByComponentUuid(componentUuid);
+  }
+
   public List<IssueDto> selectByComponentUuidPaginated(DbSession session, String componentUuid, int page) {
     return mapper(session).selectByComponentUuidPaginated(componentUuid, Pagination.forPage(page).andSize(DEFAULT_PAGE_SIZE));
   }
index 9fa98e1f39183a0355295da74fb9049ae86a3ce1..80ea1be570cd6cce1ec620a1aa07a2db8dd33269 100644 (file)
@@ -37,6 +37,8 @@ public interface IssueMapper {
 
   List<IssueDto> selectByKeys(List<String> keys);
 
+  Set<String> selectIssueKeysByComponentUuid(@Param("componentUuid") String componentUuid);
+
   List<IssueDto> selectByComponentUuidPaginated(@Param("componentUuid") String componentUuid,
                                                 @Param("pagination") Pagination pagination);
 
index ff5dc7f5735065090a5e122882657fc614a911f4..059c6f76c5374cb78abcb5fde042c0f11fe8262a 100644 (file)
     group by i2.issue_type, i2.severity, i2.resolution, i2.status, i2.inLeak
   </select>
 
+  <select id="selectIssueKeysByComponentUuid" parameterType="string" resultType="string">
+    select
+      i.kee
+    from issues i
+    where
+      i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
+  </select>
+
   <select id="selectByComponentUuidPaginated" parameterType="map" resultType="Issue">
     select
     <include refid="issueColumns"/>
     inner join components p on p.uuid=i.component_uuid
     inner join components root on root.uuid=i.project_uuid
     where i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
-    order by i.kee
+    order by i.issue_creation_date ASC
     limit #{pagination.pageSize,jdbcType=INTEGER} offset #{pagination.offset,jdbcType=INTEGER}
   </select>
 
     <include refid="issueColumns"/>
     from
     (select
-        row_number() over(order by i.kee) as row_number,
+        row_number() over(order by i.issue_creation_date ASC) as row_number,
           <include refid="issueColumnsInInnerQuery" />
         from issues i
         where i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
                <include refid="issueColumnsInInnerQuery"/>
                from issues i
                where i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
-                       order by i.kee
+                       order by i.issue_creation_date ASC
              ) t
            ) i
            where
index 691dea2e5045da69dd4825ff97ffb0098139a239..7541739759f45e5712ee7b2057f6ee9d63bf88b2 100644 (file)
@@ -23,6 +23,7 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+import java.util.Set;
 import java.util.stream.Stream;
 import org.junit.Rule;
 import org.junit.Test;
@@ -128,6 +129,17 @@ public class IssueDaoTest {
     assertThat(issues).extracting("key").containsOnly("I1", "I2");
   }
 
+  @Test
+  public void selectIssueKeysByComponentUuid() {
+    // contains I1 and I2
+    prepareTables();
+
+    Set<String> issues = underTest.selectIssueKeysByComponentUuid(db.getSession(), PROJECT_UUID);
+
+    // results are not ordered, so do not use "containsExactly"
+    assertThat(issues).containsOnly("I1", "I2");
+  }
+
   @Test
   public void selectByComponentUuidPaginated() {
     // contains I1 and I2