Skip to content

Commit 1942372

Browse files
authored
Removing getProjectSize function for efficiency. (#4466)
1 parent 16bc1a9 commit 1942372

File tree

4 files changed

+8
-46
lines changed

4 files changed

+8
-46
lines changed

plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/CodeWhispererCodeScanManager.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ import com.intellij.ui.content.ContentManagerListener
3232
import com.intellij.ui.treeStructure.Tree
3333
import kotlinx.coroutines.CancellationException
3434
import kotlinx.coroutines.CoroutineScope
35-
import kotlinx.coroutines.Deferred
3635
import kotlinx.coroutines.Job
3736
import kotlinx.coroutines.TimeoutCancellationException
38-
import kotlinx.coroutines.async
3937
import kotlinx.coroutines.delay
4038
import kotlinx.coroutines.ensureActive
4139
import kotlinx.coroutines.isActive
@@ -220,7 +218,6 @@ class CodeWhispererCodeScanManager(val project: Project) {
220218
var codeScanStatus: Result = Result.Failed
221219
val startTime = Instant.now().toEpochMilli()
222220
var codeScanResponseContext = defaultCodeScanResponseContext()
223-
var getProjectSize: Deferred<Long?> = async { null }
224221
val connection = ToolkitConnectionManager.getInstance(project).activeConnectionForFeature(CodeWhispererConnection.getInstance())
225222
var codeScanJobId: String? = null
226223
var language: CodeWhispererProgrammingLanguage = CodeWhispererUnknownLanguage.INSTANCE
@@ -270,9 +267,6 @@ class CodeWhispererCodeScanManager(val project: Project) {
270267
}
271268
LOG.info { "Security scan completed for jobID: $codeScanJobId." }
272269
}
273-
getProjectSize = async {
274-
codeScanSessionConfig.getTotalProjectSizeInBytes()
275-
}
276270
}
277271
} catch (e: Error) {
278272
if (scope == CodeWhispererConstants.CodeAnalysisScope.PROJECT) {
@@ -292,7 +286,14 @@ class CodeWhispererCodeScanManager(val project: Project) {
292286
launch {
293287
val duration = (Instant.now().toEpochMilli() - startTime).toDouble()
294288
CodeWhispererTelemetryService.getInstance().sendSecurityScanEvent(
295-
CodeScanTelemetryEvent(codeScanResponseContext, duration, codeScanStatus, getProjectSize.await()?.toDouble(), connection, scope)
289+
CodeScanTelemetryEvent(
290+
codeScanResponseContext,
291+
duration,
292+
codeScanStatus,
293+
codeScanResponseContext.payloadContext.srcPayloadSize.toDouble() ?: 0.0,
294+
connection,
295+
scope
296+
)
296297
)
297298
sendCodeScanTelemetryToServiceAPI(project, language, codeScanJobId, scope)
298299
}

plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/sessionconfig/CodeScanSessionConfig.kt

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ import com.intellij.openapi.project.guessProjectDir
99
import com.intellij.openapi.project.modules
1010
import com.intellij.openapi.vcs.changes.ChangeListManager
1111
import com.intellij.openapi.vfs.LocalFileSystem
12-
import com.intellij.openapi.vfs.VFileProperty
13-
import com.intellij.openapi.vfs.VfsUtil
1412
import com.intellij.openapi.vfs.VirtualFile
15-
import kotlinx.coroutines.TimeoutCancellationException
16-
import kotlinx.coroutines.time.withTimeout
1713
import software.aws.toolkits.core.utils.createTemporaryZipFile
1814
import software.aws.toolkits.core.utils.debug
1915
import software.aws.toolkits.core.utils.getLogger
@@ -35,7 +31,6 @@ import software.aws.toolkits.telemetry.CodewhispererLanguage
3531
import java.io.File
3632
import java.nio.file.Files
3733
import java.nio.file.Path
38-
import java.time.Duration
3934
import java.time.Instant
4035
import java.util.Stack
4136
import kotlin.io.path.relativeTo
@@ -134,30 +129,6 @@ class CodeScanSessionConfig(
134129
return bufferedReader.useLines { lines -> lines.count() }
135130
}
136131

137-
suspend fun getTotalProjectSizeInBytes(): Long {
138-
var totalSize = 0L
139-
try {
140-
withTimeout(Duration.ofSeconds(TELEMETRY_TIMEOUT_IN_SECONDS)) {
141-
if (scope == CodeAnalysisScope.FILE) {
142-
totalSize = selectedFile?.length ?: 0L
143-
} else {
144-
val changeListManager = ChangeListManager.getInstance(project)
145-
VfsUtil.collectChildrenRecursively(projectRoot).filter {
146-
!it.isDirectory && !it.`is`((VFileProperty.SYMLINK)) && (
147-
!changeListManager.isIgnoredFile(it)
148-
)
149-
}.fold(0L) { acc, next ->
150-
totalSize = acc + next.length
151-
totalSize
152-
}
153-
}
154-
}
155-
} catch (e: TimeoutCancellationException) {
156-
// Do nothing
157-
}
158-
return totalSize
159-
}
160-
161132
private fun zipFiles(files: List<Path>): File = createTemporaryZipFile {
162133
files.forEach { file ->
163134
val relativePath = file.relativeTo(projectRoot.toNioPath())
@@ -235,7 +206,6 @@ class CodeScanSessionConfig(
235206

236207
companion object {
237208
private val LOG = getLogger<CodeScanSessionConfig>()
238-
private const val TELEMETRY_TIMEOUT_IN_SECONDS: Long = 10
239209
fun create(file: VirtualFile?, project: Project, scope: CodeAnalysisScope): CodeScanSessionConfig = CodeScanSessionConfig(file, project, scope)
240210
}
241211
}

plugins/toolkit/jetbrains-core/tst/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/CodeWhispererCodeScanTestBase.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,6 @@ open class CodeWhispererCodeScanTestBase(projectRule: CodeInsightTestFixtureRule
226226
]
227227
"""
228228

229-
internal fun getTotalProjectSizeInBytes(sessionConfigSpy: CodeScanSessionConfig, totalSize: Long) = runBlocking {
230-
assertThat(sessionConfigSpy.getTotalProjectSizeInBytes()).isEqualTo(totalSize)
231-
}
232-
233229
internal fun selectedFileLargerThanPayloadSizeThrowsException(sessionConfigSpy: CodeScanSessionConfig) {
234230
sessionConfigSpy.stub {
235231
onGeneric { getPayloadLimitInBytes() }.thenReturn(100)

plugins/toolkit/jetbrains-core/tst/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/CodeWhispererProjectCodeScanTest.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,6 @@ class CodeWhispererProjectCodeScanTest : CodeWhispererCodeScanTestBase(PythonCod
8686
getProjectPayloadMetadata(sessionConfigSpy, 10, totalSize, this.totalLines, CodewhispererLanguage.Csharp)
8787
}
8888

89-
@Test
90-
fun `test getTotalProjectSizeInBytes()`() {
91-
getTotalProjectSizeInBytes(sessionConfigSpy, this.totalSize)
92-
}
93-
9489
@Test
9590
fun `selected file larger than payload limit throws exception`() {
9691
selectedFileLargerThanPayloadSizeThrowsException(sessionConfigSpy)

0 commit comments

Comments
 (0)