Browse Source

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
tags/8.0
Sébastien Lesaint 4 years ago
parent
commit
d17f0721a3

+ 1
- 1
server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml View File

@@ -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})
</update>

<delete id="deleteRuleProfilesByUuids" parameterType="String">

+ 14
- 1
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java View File

@@ -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);

Loading…
Cancel
Save