Skip to content

Commit 6af4d44

Browse files
Stop listing all files POC
1 parent a31f5d8 commit 6af4d44

File tree

7 files changed

+38
-8
lines changed

7 files changed

+38
-8
lines changed

backend/core/src/main/java/org/sonarsource/sonarlint/core/fs/FileExclusionService.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ public FileExclusionService(ConfigurationRepository configRepo, StorageService s
9898
}
9999

100100
public boolean computeIfExcluded(URI fileUri, SonarLintCancelMonitor cancelMonitor) {
101-
LOG.debug("Computing file exclusion for uri '{}'", fileUri);
102101
var clientFile = clientFileSystemService.getClientFile(fileUri);
103102
if (clientFile == null) {
104103
LOG.debug("Unable to find client file for uri {}", fileUri);
@@ -140,7 +139,6 @@ public boolean computeIfExcluded(URI fileUri, SonarLintCancelMonitor cancelMonit
140139
}
141140
var type = clientFile.isTest() ? InputFile.Type.TEST : InputFile.Type.MAIN;
142141
var result = !exclusionFilters.accept(serverPath.toString(), type);
143-
LOG.debug("File exclusion for uri '{}' is {}", fileUri, result);
144142
return result;
145143
}
146144

backend/core/src/main/java/org/sonarsource/sonarlint/core/sync/FindingsSynchronizationService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
package org.sonarsource.sonarlint.core.sync;
2121

2222
import java.nio.file.Path;
23+
import java.time.Instant;
2324
import java.util.LinkedList;
2425
import java.util.Set;
2526
import java.util.concurrent.CompletableFuture;
2627
import java.util.concurrent.ExecutorService;
2728
import java.util.stream.Collectors;
2829
import org.sonarsource.sonarlint.core.branch.SonarProjectBranchTrackingService;
2930
import org.sonarsource.sonarlint.core.commons.Binding;
31+
import org.sonarsource.sonarlint.core.commons.log.SonarLintLogger;
3032
import org.sonarsource.sonarlint.core.commons.progress.SonarLintCancelMonitor;
3133
import org.sonarsource.sonarlint.core.commons.util.FailSafeExecutors;
3234
import org.sonarsource.sonarlint.core.file.FilePathTranslation;
@@ -36,6 +38,7 @@
3638
import org.sonarsource.sonarlint.core.rpc.protocol.backend.initialize.InitializeParams;
3739

3840
public class FindingsSynchronizationService {
41+
private static final SonarLintLogger LOG = SonarLintLogger.get();
3942
private static final int FETCH_ALL_ISSUES_THRESHOLD = 10;
4043
private final ConfigurationRepository configurationRepository;
4144
private final SonarProjectBranchTrackingService branchTrackingService;
@@ -58,6 +61,7 @@ public FindingsSynchronizationService(ConfigurationRepository configurationRepos
5861
}
5962

6063
public void refreshServerFindings(String configurationScopeId, Set<Path> pathsToRefresh) {
64+
LOG.debug("Refreshing server findings for configuration scope: {}", configurationScopeId);
6165
var effectiveBindingOpt = configurationRepository.getEffectiveBinding(configurationScopeId);
6266
var activeBranchOpt = branchTrackingService.awaitEffectiveSonarProjectBranch(configurationScopeId);
6367
var translationOpt = pathTranslationService.getOrComputePathTranslation(configurationScopeId);
@@ -75,9 +79,12 @@ public void refreshServerFindings(String configurationScopeId, Set<Path> pathsTo
7579

7680
private void refreshServerIssues(SonarLintCancelMonitor cancelMonitor, Binding binding, String activeBranch,
7781
Set<Path> pathsInvolved, FilePathTranslation translation) {
82+
LOG.debug("Refreshing server issues for binding: {}, active branch: {}", binding, activeBranch);
7883
var serverFileRelativePaths = pathsInvolved.stream().map(translation::ideToServerPath).collect(Collectors.toSet());
7984
var downloadAllIssuesAtOnce = serverFileRelativePaths.size() > FETCH_ALL_ISSUES_THRESHOLD;
8085
var fetchTasks = new LinkedList<CompletableFuture<?>>();
86+
LOG.debug("Fetching issues");
87+
var now = Instant.now();
8188
if (downloadAllIssuesAtOnce) {
8289
fetchTasks.add(CompletableFuture.runAsync(() -> issueSynchronizationService.fetchProjectIssues(binding, activeBranch, cancelMonitor), issueUpdaterExecutorService));
8390
} else {
@@ -87,6 +94,7 @@ private void refreshServerIssues(SonarLintCancelMonitor cancelMonitor, Binding b
8794
.toList());
8895
}
8996
CompletableFuture.allOf(fetchTasks.toArray(new CompletableFuture[0])).join();
97+
LOG.debug("Fetching issues took {} ms", Instant.now().toEpochMilli() - now.toEpochMilli());
9098
}
9199

92100
private void refreshServerSecurityHotspots(SonarLintCancelMonitor cancelMonitor, Binding binding, String activeBranch,

backend/core/src/main/java/org/sonarsource/sonarlint/core/sync/IssueSynchronizationService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ public void syncServerIssuesForProject(ServerApi serverApi, String connectionId,
6161
}
6262

6363
public void fetchProjectIssues(Binding binding, String activeBranch, SonarLintCancelMonitor cancelMonitor) {
64+
LOG.debug("Start downloading issues from SonarQube - fetchProjectIssues");
6465
sonarQubeClientManager.withActiveClient(binding.connectionId(), serverApi ->
6566
downloadServerIssuesForProject(binding.connectionId(), serverApi, binding.sonarProjectKey(), activeBranch, cancelMonitor));
6667
}
6768

6869
private void downloadServerIssuesForProject(String connectionId, ServerApi serverApi, String projectKey, String branchName, SonarLintCancelMonitor cancelMonitor) {
70+
LOG.info("[SYNC] Synchronizing issues for project '{}' on branch '{}'", projectKey, branchName);
6971
var storage = storageService.connection(connectionId);
7072
var enabledLanguagesToSync = languageSupportRepository.getEnabledLanguagesInConnectedMode().stream().filter(SonarLanguage::shouldSyncInConnectedMode)
7173
.collect(Collectors.toCollection(LinkedHashSet::new));

backend/core/src/main/java/org/sonarsource/sonarlint/core/tracking/TrackingService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ public void onAnalysisFailed(AnalysisFailedEvent event) {
150150

151151
@EventListener
152152
public void onAnalysisFinished(AnalysisFinishedEvent event) {
153+
LOG.debug("Analysis finished: {}", event);
153154
var analysisId = event.getAnalysisId();
154155
var matchingSession = matchingSessionByAnalysisId.remove(analysisId);
155156
if (matchingSession == null) {

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.sonarsource.sonarlint.core.serverconnection;
2121

2222
import java.nio.file.Path;
23+
import java.time.Instant;
2324
import java.util.ArrayList;
2425
import java.util.List;
2526
import java.util.Set;
@@ -29,6 +30,7 @@
2930
import org.sonarsource.sonarlint.core.serverapi.ServerApi;
3031
import org.sonarsource.sonarlint.core.serverconnection.issues.ServerIssue;
3132
import org.sonarsource.sonarlint.core.serverconnection.issues.ServerTaintIssue;
33+
import org.sonarsource.sonarlint.core.serverconnection.storage.ProjectServerIssueStore;
3234
import org.sonarsource.sonarlint.core.serverconnection.storage.UpdateSummary;
3335

3436
import static java.util.stream.Collectors.toSet;
@@ -50,8 +52,16 @@ public ServerIssueUpdater(ConnectionStorage storage, IssueDownloader issueDownlo
5052

5153
public void update(ServerApi serverApi, String projectKey, String branchName, SonarLintCancelMonitor cancelMonitor) {
5254
if (serverApi.isSonarCloud()) {
55+
LOG.debug("Start downloading issues from SonarQube Cloud");
56+
var start = Instant.now();
5357
var issues = issueDownloader.downloadFromBatch(serverApi, projectKey, branchName, cancelMonitor);
54-
storage.project(projectKey).findings().replaceAllIssuesOfBranch(branchName, issues);
58+
var finishedDownload = Instant.now();
59+
LOG.debug("Finished downloading {} issues from SonarQube Cloud in {} ms", issues.size(), finishedDownload.toEpochMilli() - start.toEpochMilli());
60+
var issueStore = storage.project(projectKey).findings();
61+
LOG.debug("Issue store type: {}", issueStore.getClass().getSimpleName());
62+
issueStore.replaceAllIssuesOfBranch(branchName, issues);
63+
var finishedWritingToStorage = Instant.now();
64+
LOG.debug("Finished updating {} issues in storage in {} ms", issues.size(), finishedWritingToStorage.toEpochMilli() - finishedDownload.toEpochMilli());
5565
} else {
5666
sync(serverApi, projectKey, branchName, issueDownloader.getEnabledLanguages(), cancelMonitor);
5767
}
@@ -61,10 +71,13 @@ public void sync(ServerApi serverApi, String projectKey, String branchName, Set<
6171
var lastSync = storage.project(projectKey).findings().getLastIssueSyncTimestamp(branchName);
6272

6373
lastSync = computeLastSync(enabledLanguages, lastSync, storage.project(projectKey).findings().getLastIssueEnabledLanguages(branchName));
64-
74+
Instant start = Instant.now();
6575
var result = issueDownloader.downloadFromPull(serverApi, projectKey, branchName, lastSync, cancelMonitor);
76+
var downloadTime = Instant.now();
77+
LOG.debug("Downloaded {} issues took {}", result.getChangedIssues().size(), downloadTime.toEpochMilli() - start.toEpochMilli());
6678
storage.project(projectKey).findings().mergeIssues(branchName, result.getChangedIssues(), result.getClosedIssueKeys(),
6779
result.getQueryTimestamp(), enabledLanguages);
80+
LOG.debug("Finished updating {} issues in storage in {} ms", result.getChangedIssues().size(), Instant.now().toEpochMilli() - downloadTime.toEpochMilli());
6881
}
6982

7083
public UpdateSummary<ServerTaintIssue> syncTaints(ServerApi serverApi, String projectKey, String branchName, Set<SonarLanguage> enabledLanguages,

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.sonarsource.sonarlint.core.serverconnection.storage;
2121

2222
import java.nio.file.Path;
23+
import java.time.Duration;
2324
import java.time.Instant;
2425
import java.time.LocalDateTime;
2526
import java.time.ZoneId;
@@ -34,6 +35,7 @@
3435
import org.jooq.TableField;
3536
import org.sonarsource.sonarlint.core.commons.HotspotReviewStatus;
3637
import org.sonarsource.sonarlint.core.commons.api.SonarLanguage;
38+
import org.sonarsource.sonarlint.core.commons.log.SonarLintLogger;
3739
import org.sonarsource.sonarlint.core.commons.storage.SonarLintDatabase;
3840
import org.sonarsource.sonarlint.core.commons.storage.model.Tables;
3941
import org.sonarsource.sonarlint.core.commons.storage.model.tables.records.ServerBranchesRecord;
@@ -48,7 +50,7 @@
4850
import static org.sonarsource.sonarlint.core.commons.storage.model.Tables.SERVER_DEPENDENCY_RISKS;
4951

5052
public class ServerFindingRepository implements ProjectServerIssueStore {
51-
53+
private static final SonarLintLogger LOG = SonarLintLogger.get();
5254
private final EntityMapper mapper = new EntityMapper();
5355
private final SonarLintDatabase database;
5456
private final String connectionId;
@@ -215,7 +217,7 @@ public Optional<Instant> getLastIssueSyncTimestamp(String branchName) {
215217
.and(SERVER_BRANCHES.CONNECTION_ID.eq(connectionId))
216218
.and(SERVER_BRANCHES.SONAR_PROJECT_KEY.eq(sonarProjectKey)))
217219
.fetchOne();
218-
if (rec == null) {
220+
if (rec == null || rec.value1() == null) {
219221
return Optional.empty();
220222
}
221223
var ldt = rec.value1();
@@ -245,7 +247,7 @@ public Optional<Instant> getLastTaintSyncTimestamp(String branchName) {
245247
.and(SERVER_BRANCHES.CONNECTION_ID.eq(connectionId))
246248
.and(SERVER_BRANCHES.SONAR_PROJECT_KEY.eq(sonarProjectKey)))
247249
.fetchOne();
248-
if (rec == null) {
250+
if (rec == null || rec.value1() == null) {
249251
return Optional.empty();
250252
}
251253
var ldt = rec.value1();
@@ -260,7 +262,7 @@ public Optional<Instant> getLastHotspotSyncTimestamp(String branchName) {
260262
.and(SERVER_BRANCHES.CONNECTION_ID.eq(connectionId))
261263
.and(SERVER_BRANCHES.SONAR_PROJECT_KEY.eq(sonarProjectKey)))
262264
.fetchOne();
263-
if (rec == null) {
265+
if (rec == null || rec.get(0, LocalDateTime.class) == null) {
264266
return Optional.empty();
265267
}
266268
var ldt = rec.get(0, LocalDateTime.class);
@@ -563,9 +565,12 @@ private void batchMergeHotspots(String branchName, String connectionId, String s
563565
}
564566

565567
private void batchMergeIssues(String branchName, String connectionId, String sonarProjectKey, Configuration trx, Collection<ServerIssue<?>> issues) {
568+
LOG.debug("Batch merging {} issues for branch '{}' and project '{}'", issues.size(), branchName, sonarProjectKey);
569+
var start = Instant.now();
566570
trx.dsl().batchMerge(issues.stream()
567571
.map(issue -> mapper.serverIssueToRecord(issue, branchName, connectionId, sonarProjectKey)).toList())
568572
.execute();
573+
LOG.debug("Batch merge completed in {} ms", Duration.between(start, Instant.now()).toMillis());
569574
}
570575

571576
private void batchMergeTaints(String branchName, String connectionId, String sonarProjectKey, Configuration trx, Collection<ServerTaintIssue> taints) {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,8 @@ public boolean wasEverUpdated() {
484484

485485
@Override
486486
public void replaceAllIssuesOfBranch(String branchName, List<ServerIssue<?>> issues) {
487+
LOG.debug("Replacing all issues of branch {} with {} issues", branchName, issues.size());
488+
var start = Instant.now();
487489
var issuesByFile = issues.stream().collect(Collectors.groupingBy(ServerIssue::getFilePath));
488490
timed(wroteMessage(issues.size(), ISSUES), () -> entityStore.executeInTransaction(txn -> {
489491
var branch = getOrCreateBranch(branchName, txn);
@@ -501,6 +503,7 @@ public void replaceAllIssuesOfBranch(String branchName, List<ServerIssue<?>> iss
501503
txn.flush();
502504
});
503505
}));
506+
LOG.debug("Finished replacing all issues of branch {} in {} ms", branchName, Duration.between(start, Instant.now()).toMillis());
504507
}
505508

506509
@Override

0 commit comments

Comments
 (0)