From: Sébastien Lesaint Date: Wed, 9 Oct 2019 10:47:08 +0000 (+0200) Subject: SONAR-12513 last used date is never set on new Quality Profiles X-Git-Tag: 7.9.2~9 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f8add7c8bb37aba2c9b1cbdb0957e9d831d9f216;p=sonarqube.git SONAR-12513 last used date is never set on new Quality Profiles all QP start with no last used date in the Database, which is represented by a null value in the column, the update method ensures no update is done if new date is older than the current one it does so by comparing the new date with the current value, however, this test always returns false if the current value is null this way of updating the last used date was introduced to fix SONAR-10462 (Update of last used date on Quality Profile can fail with Deadlock on Postgres) since then, last used date of new QP (which includes any new install of SQ since 7.8, including the LTS) is never set --- diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml index dcbdaefe4ea..5a74720b17a 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml @@ -98,7 +98,7 @@ updated_at = #{now, jdbcType=BIGINT} where uuid = #{uuid, jdbcType=VARCHAR} - and last_used < #{lastUsedDate, jdbcType=BIGINT} + and (last_used is null or last_used < #{lastUsedDate, jdbcType=BIGINT}) diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java index b27df5e28cf..a05098c9525 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java @@ -149,7 +149,20 @@ public class QualityProfileDaoTest { } @Test - public void test_updateLastUsedDate() { + public void test_updateLastUsedDate_if_never_been_set_yet() { + QProfileDto initial = QualityProfileTesting.newQualityProfileDto() + .setLastUsed(null); + underTest.insert(dbSession, initial); + + int count = underTest.updateLastUsedDate(dbSession, initial, 15_000L); + + assertThat(count).isEqualTo(1); + QProfileDto reloaded = underTest.selectByUuid(dbSession, initial.getKee()); + assertThat(reloaded.getLastUsed()).isEqualTo(15_000L); + } + + @Test + public void test_updateLastUsedDate_if_more_recent() { QProfileDto initial = QualityProfileTesting.newQualityProfileDto() .setLastUsed(10_000L); underTest.insert(dbSession, initial);