-
Notifications
You must be signed in to change notification settings - Fork 341
feat(npm): Speed-up getting the remote package details #10059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,11 @@ | |
import java.io.File | ||
import java.util.LinkedList | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.async | ||
import kotlinx.coroutines.awaitAll | ||
import kotlinx.coroutines.withContext | ||
|
||
import org.apache.logging.log4j.kotlin.logger | ||
|
||
import org.ossreviewtoolkit.analyzer.PackageManagerFactory | ||
|
@@ -45,6 +50,7 @@ | |
import org.ossreviewtoolkit.utils.common.ProcessCapture | ||
import org.ossreviewtoolkit.utils.common.collectMessages | ||
import org.ossreviewtoolkit.utils.common.withoutPrefix | ||
import org.ossreviewtoolkit.utils.ort.runBlocking | ||
|
||
import org.semver4j.RangesList | ||
import org.semver4j.RangesListFactory | ||
|
@@ -126,6 +132,9 @@ | |
val project = parseProject(definitionFile, analysisRoot) | ||
val projectModuleInfo = listModules(workingDir, issues).undoDeduplication() | ||
|
||
// Warm-up the cache to speed-up processing. | ||
requestAllPackageDetails(projectModuleInfo) | ||
|
||
val scopeNames = Scope.entries | ||
.filterNot { excludes.isScopeExcluded(it.descriptor) } | ||
.mapTo(mutableSetOf()) { scope -> | ||
|
@@ -179,13 +188,41 @@ | |
|
||
return process.extractNpmIssues() | ||
} | ||
|
||
private fun requestAllPackageDetails(projectModuleInfo: ModuleInfo) { | ||
runBlocking { | ||
withContext(Dispatchers.IO.limitedParallelism(20)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this special value ? Is it from empirical testing ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It aligns with other similar code that was introduced by @mnonnenmacher in 23c9bb0. But I agree that we should afterwards probably extract a constant. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In 23c9bb0 |
||
projectModuleInfo.getAllPackageNodeModuleIds().map { packageName -> | ||
async { getRemotePackageDetails(packageName) } | ||
}.awaitAll() | ||
} | ||
} | ||
} | ||
} | ||
|
||
private enum class Scope(val descriptor: String) { | ||
DEPENDENCIES("dependencies"), | ||
DEV_DEPENDENCIES("devDependencies") | ||
} | ||
|
||
private fun ModuleInfo.getAllPackageNodeModuleIds(): Set<String> { | ||
val queue = Scope.entries.flatMapTo(LinkedList()) { getScopeDependencies(it) } | ||
val result = mutableSetOf<String>() | ||
sschuberth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
while (queue.isNotEmpty()) { | ||
val info = queue.removeFirst() | ||
|
||
@Suppress("ComplexCondition") | ||
if (!info.isProject && info.isInstalled && !info.name.isNullOrBlank() && !info.version.isNullOrBlank()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity: Aren't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For the record, here's what I did to confirm that statement for my own confidence. Drilling down,
and
(emphasis mine, as that's the part that confused me). Also, But the root project itself seems to be an exception to that. Running |
||
result += "${info.name}@${info.version}" | ||
} | ||
|
||
Scope.entries.flatMapTo(queue) { info.getScopeDependencies(it) } | ||
} | ||
|
||
return result | ||
} | ||
|
||
private fun ModuleInfo.getScopeDependencies(scope: Scope) = | ||
when (scope) { | ||
Scope.DEPENDENCIES -> dependencies.values.filter { !it.dev } | ||
|
Uh oh!
There was an error while loading. Please reload this page.