Skip to content

Commit

Permalink
fix: cache cleaning and some name refactorings [IDE-134] (#480)
Browse files Browse the repository at this point in the history
* fix: cache clearing and logging

* refactor: rename `processAfterForLS` to `updateCacheAndUI`

* refactor: rename `buildHMLpostfix` to `buildSeveritiesPostfix`
  • Loading branch information
bastiandoetsch authored Mar 5, 2024
1 parent b541b58 commit 43b83b3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class SnykCodeBulkFileListener : SnykBulkFileListener() {
val filesAffected = toSnykCodeFileSet(project, virtualFilesAffected)

if (isSnykCodeLSEnabled()) {
processAfterForLS(filesAffected, project)
updateCacheAndUI(filesAffected, project)
return
}
/* update .dcignore caches if needed */
Expand All @@ -98,7 +98,7 @@ class SnykCodeBulkFileListener : SnykBulkFileListener() {
}
}

private fun processAfterForLS(filesAffected: Set<SnykCodeFile>, project: Project) {
private fun updateCacheAndUI(filesAffected: Set<SnykCodeFile>, project: Project) {
val cache = getSnykCachedResults(project)?.currentSnykCodeResultsLS ?: return
filesAffected.forEach {
cache.remove(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class SnykToolWindowSnykCodeScanListenerLS(
.map { it.key to it.value.filter { issue -> issue.additionalData.isSecurityType } }
.toMap()
securityIssuesCount = securityResults.values.flatten().distinct().size
securityIssuesHMLPostfix = buildHMLpostfix(securityResults)
securityIssuesHMLPostfix = buildSeveritiesPostfixForFileNode(securityResults)

if (pluginSettings().treeFiltering.codeSecurityResults) {
val securityResultsToDisplay = securityResults.map { entry ->
Expand Down Expand Up @@ -103,7 +103,7 @@ class SnykToolWindowSnykCodeScanListenerLS(
.map { it.key to it.value.filter { issue -> !issue.additionalData.isSecurityType } }
.toMap()
qualityIssuesCount = qualityResults.values.flatten().distinct().size
qualityIssuesHMLPostfix = buildHMLpostfix(qualityResults)
qualityIssuesHMLPostfix = buildSeveritiesPostfixForFileNode(qualityResults)

if (pluginSettings().treeFiltering.codeQualityResults) {
val qualityResultsToDisplay = qualityResults.map { entry ->
Expand Down Expand Up @@ -157,7 +157,7 @@ class SnykToolWindowSnykCodeScanListenerLS(
}
}

private fun buildHMLpostfix(securityResults: Map<SnykCodeFile, List<ScanIssue>>): String {
private fun buildSeveritiesPostfixForFileNode(securityResults: Map<SnykCodeFile, List<ScanIssue>>): String {
val high = securityResults.values.flatten().count { it.getSeverityAsEnum() == Severity.HIGH }
val medium = securityResults.values.flatten().count { it.getSeverityAsEnum() == Severity.MEDIUM }
val low = securityResults.values.flatten().count { it.getSeverityAsEnum() == Severity.LOW }
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/snyk/common/SnykCachedResults.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SnykCachedResults(val project: Project) {
currentOssError = null
currentContainerError = null
currentIacError = null
// currentSnykCodeResultsLS = null
currentSnykCodeResultsLS.clear()
currentSnykCodeResults = null
currentSnykCodeError = null
}
Expand Down Expand Up @@ -125,7 +125,7 @@ class SnykCachedResults(val project: Project) {
object : SnykCodeScanListenerLS {
val logger = logger<SnykCachedResults>()
override fun scanningStarted(snykScan: SnykScanParams) {
logger.info("scanningStarted for project ${project.name}, emptying cache.")
logger.info("scanningStarted for project ${project.name}")
}

override fun scanningSnykCodeFinished(snykCodeResults: Map<SnykCodeFile, List<ScanIssue>>) {
Expand Down

0 comments on commit 43b83b3

Please sign in to comment.