Improve performance of API calls #1538 - #1547
Merged
Merged
Conversation
Reference:#1538 Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Remove unused imports Move univers monkey patching to top level Reference:#1538 Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
* is_vulnerable is now a queryset annotation. * with_is_vulnerable Package manager method annotates the queryset * It is now called anywhere needed. The results with a single API call to http://127.0.0.1:8001/api/packages/63 are: * before 1.7 sec * after 0.25 sec Or an improvement where the old is 6.8 times slower than the new. Reference:#1538 Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
* simplify sorting code, revert to using lists * use cached_property where relevant Reference:#1538 Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
* Fix how we find vulnerable and non vulnerable versions * Complete using is_vulnerable in relevant querysets. * Adjust tests for clarity and DRY using small method to make the tests setup easier to read * Use proper typing annotation for PackageURL or str * Add new Package manager from_purl() method to create a Package from a PURL Reference:#1538 Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR tries to improve the API lookup calls.
One hotspot is the the
Package.is_vulnerableproperty that runs an exists() on a querysetin a repeated manner.
To avoid this, the approach is to annotate the Package queryset(s) with an
is_vulnerableattribute.
The results with a single API call to http://127.0.0.1:8001/api/packages/63 are like this
using pyinstrument and django-toolbar on a laptop:
Before
The pyinstrument hotspot are calls to:
After:
Or an improvement looking like this:
Reference:#1538
Signed-off-by: Philippe Ombredanne pombredanne@nexb.com