Skip to content

Commit 496da8d

Browse files
SLCORE-1858 Fix 'was ever updated' check for ServerFindingRepository
1 parent df65aaf commit 496da8d

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

backend/server-connection/src/main/java/org/sonarsource/sonarlint/core/serverconnection/storage/ServerFindingRepository.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,13 @@ public ServerFindingRepository(SonarLintDatabase database, String connectionId,
6464

6565
@Override
6666
public boolean wasEverUpdated() {
67-
// Limit to current connection/project scope
68-
var rec = database.dsl().select(SERVER_BRANCHES.LAST_ISSUE_SYNC_TS).from(SERVER_BRANCHES)
67+
return database.dsl().select(SERVER_BRANCHES.LAST_ISSUE_SYNC_TS, SERVER_BRANCHES.LAST_HOTSPOT_SYNC_TS, SERVER_BRANCHES.LAST_TAINT_SYNC_TS)
68+
.from(SERVER_BRANCHES)
6969
.where(SERVER_BRANCHES.CONNECTION_ID.eq(connectionId)
7070
.and(SERVER_BRANCHES.SONAR_PROJECT_KEY.eq(sonarProjectKey)))
71-
.fetchAny();
72-
return rec != null && rec.value1() != null;
71+
.fetchOptional()
72+
.filter(r -> r.value1() != null || r.value2() != null || r.value3() != null)
73+
.isPresent();
7374
}
7475

7576
@Override

backend/server-connection/src/test/java/org/sonarsource/sonarlint/core/serverconnection/storage/ServerFindingRepositoryTests.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,34 @@ void was_ever_updated() {
192192
assertThat(repo.wasEverUpdated()).isTrue();
193193
}
194194

195+
@Test
196+
void was_ever_updated_for_no_issues() {
197+
repo.replaceAllIssuesOfBranch(branch, List.of(), Set.of());
198+
199+
assertThat(repo.wasEverUpdated()).isTrue();
200+
}
201+
202+
@Test
203+
void was_never_updated() {
204+
assertThat(repo.wasEverUpdated()).isFalse();
205+
}
206+
207+
@Test
208+
void was_ever_updated_when_only_hotspots_synced() {
209+
var h1 = hotspot("HOTSPOT_KEY_1", filePath, 1, HotspotReviewStatus.TO_REVIEW, VulnerabilityProbability.MEDIUM, null);
210+
repo.mergeHotspots(branch, List.of(h1), Set.of(), Instant.now(), Set.of());
211+
212+
assertThat(repo.wasEverUpdated()).isTrue();
213+
}
214+
215+
@Test
216+
void was_ever_updated_when_only_taints_synced() {
217+
var t1 = taint("TAINT_KEY_1", filePath);
218+
repo.mergeTaintIssues(branch, List.of(t1), Set.of(), Instant.now(), Set.of());
219+
220+
assertThat(repo.wasEverUpdated()).isTrue();
221+
}
222+
195223
@Test
196224
void update_issue_resolution_status() {
197225
var issueKey = "ISSUE_KEY";

0 commit comments

Comments
 (0)