Skip to content

Commit

Permalink
fix(fossid-webapp): List snippets concurrently
Browse files Browse the repository at this point in the history
When the usage of the Flow was introduced, snippets were listed
sequentially for a given file. This commit enforce concurrency again.

Signed-off-by: Nicolas Nobelis <[email protected]>
  • Loading branch information
nnobelis committed May 13, 2024
1 parent 1ece1bb commit a9811b0
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions plugins/scanners/fossid/src/main/kotlin/FossId.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.runBlocking
Expand Down Expand Up @@ -877,14 +878,19 @@ class FossId internal constructor(
if (config.fetchSnippetMatchedLines) {
logger.info { "Listing snippet matched lines for $file..." }

filteredSnippets.filter { it.matchType == MatchType.PARTIAL }.map { snippet ->
val matchedLinesResponse =
service.listMatchedLines(config.user, config.apiKey, scanCode, file, snippet.id)
.checkResponse("list snippets matched lines")
val lines = checkNotNull(matchedLinesResponse.data) {
"Matched lines could not be listed. Response was ${matchedLinesResponse.message}."
}
matchedLines[snippet.id] = lines
coroutineScope {
filteredSnippets.filter { it.matchType == MatchType.PARTIAL }.map { snippet ->
async {
val matchedLinesResponse =
service.listMatchedLines(config.user, config.apiKey, scanCode, file, snippet.id)
.checkResponse("list snippets matched lines")
val lines = checkNotNull(matchedLinesResponse.data) {
"Matched lines could not be listed. Response was " +
"${matchedLinesResponse.message}."
}
matchedLines[snippet.id] = lines
}
}.awaitAll()
}
}
emit(file to filteredSnippets.toSet())
Expand Down

0 comments on commit a9811b0

Please sign in to comment.