Skip to content

Commit 6b006bd

Browse files
committed
Avoid iceberg queries
And streamline template Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent 0f2e18a commit 6b006bd

3 files changed

Lines changed: 25 additions & 26 deletions

File tree

vulnerabilities/api.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,10 @@ def bulk_search(self, request):
256256

257257
@action(detail=False, methods=["get"])
258258
def all(self, request):
259-
vulnerable_packages = Package.objects.vulnerable().only(*PackageURL._fields)
259+
"""
260+
Return all the vulnerable Package URLs.
261+
"""
262+
vulnerable_packages = Package.objects.vulnerable().only(*PackageURL._fields).distinct()
260263
vulnerable_purls = [str(package.purl) for package in vulnerable_packages]
261264
return Response(vulnerable_purls)
262265

vulnerabilities/templates/vulnerability_details.html

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,11 @@
210210
<table class="table is-bordered is-striped is-narrow is-hoverable is-fullwidth">
211211
<thead>
212212
<tr>
213-
<th><span class="has-tooltip-multiline has-tooltip-black has-tooltip-arrow has-tooltip-text-left" data-tooltip="The package url or purl is a URL string used to identify and locate a software package.">Package URL</span></th>
214-
<th style="width: 225px;"><span class="has-tooltip-multiline has-tooltip-black has-tooltip-arrow has-tooltip-text-left" data-tooltip="This is the number of vulnerabilities that affect the package.">Affected by vulnerabilities</span></th>
215-
<th style="width: 225px;"><span class="has-tooltip-multiline has-tooltip-black has-tooltip-arrow has-tooltip-text-left" data-tooltip="This is the number of vulnerabilities fixed by the package.">Fixing vulnerabilities</span></th>
213+
<th><span
214+
class="has-tooltip-multiline has-tooltip-black has-tooltip-arrow has-tooltip-text-left"
215+
data-tooltip="The package url or purl is a URL string used to identify and locate a software package.">
216+
Package URL</span>
217+
</th>
216218
</tr>
217219
</thead>
218220
<tbody>
@@ -221,12 +223,10 @@
221223
<td>
222224
<a href="{{ package.get_absolute_url }}?search={{ package.purl }}" target="_self">{{ package.purl }}</a>
223225
</td>
224-
<td>{{ package.vulnerability_count }}</td>
225-
<td>{{ package.patched_vulnerability_count }}</td>
226226
</tr>
227227
{% empty %}
228228
<tr>
229-
<td colspan="3">
229+
<td>
230230
This vulnerability is not known to affect any packages.
231231
</td>
232232
</tr>
@@ -239,9 +239,11 @@
239239
<table class="table is-bordered is-striped is-narrow is-hoverable is-fullwidth">
240240
<thead>
241241
<tr>
242-
<th><span class="has-tooltip-multiline has-tooltip-black has-tooltip-arrow has-tooltip-text-left" data-tooltip="The package url or purl is a URL string used to identify and locate a software package.">Package URL</span></th>
243-
<th style="width: 225px;"><span class="has-tooltip-multiline has-tooltip-black has-tooltip-arrow has-tooltip-text-left" data-tooltip="This is the number of vulnerabilities that affect the package.">Affected by vulnerabilities</span></th>
244-
<th style="width: 225px;"><span class="has-tooltip-multiline has-tooltip-black has-tooltip-arrow has-tooltip-text-left" data-tooltip="This is the number of vulnerabilities fixed by the package.">Fixing vulnerabilities</span></th>
242+
<th><span
243+
class="has-tooltip-multiline has-tooltip-black has-tooltip-arrow has-tooltip-text-left"
244+
data-tooltip="The package url or purl is a URL string used to identify and locate a software package.">
245+
Package URL</span>
246+
</th>
245247
</tr>
246248
</thead>
247249
<tbody>
@@ -250,12 +252,10 @@
250252
<td>
251253
<a href="{{ package.get_absolute_url }}?search={{ package.purl }}" target="_self">{{ package.purl }}</a>
252254
</td>
253-
<td>{{ package.vulnerability_count }}</td>
254-
<td>{{ package.patched_vulnerability_count }}</td>
255255
</tr>
256256
{% empty %}
257257
<tr>
258-
<td colspan="3">
258+
<td>
259259
This vulnerability is not known to be fixed by any packages.
260260
</td>
261261
</tr>

vulnerabilities/views.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,13 @@ def get_queryset(self, query=None):
146146
Q(references__id__icontains=query) | Q(summary__icontains=query)
147147
)
148148

149-
return (
150-
qssearch.order_by("vulnerability_id")
151-
.annotate(
152-
vulnerable_package_count=Count(
153-
"packages", filter=Q(packagerelatedvulnerability__fix=False), distinct=True
154-
),
155-
patched_package_count=Count(
156-
"packages", filter=Q(packagerelatedvulnerability__fix=True), distinct=True
157-
),
158-
)
159-
.prefetch_related()
149+
return qssearch.order_by("vulnerability_id").annotate(
150+
vulnerable_package_count=Count(
151+
"packages", filter=Q(packagerelatedvulnerability__fix=False), distinct=True
152+
),
153+
patched_package_count=Count(
154+
"packages", filter=Q(packagerelatedvulnerability__fix=True), distinct=True
155+
),
160156
)
161157

162158

@@ -213,8 +209,8 @@ def get_context_data(self, **kwargs):
213209
"severities": list(self.object.severities),
214210
"references": self.object.references.all(),
215211
"aliases": self.object.aliases.all(),
216-
"resolved_to": self.object.resolved_to.with_vulnerability_counts(),
217-
"vulnerable_to": self.object.vulnerable_to.with_vulnerability_counts(),
212+
"resolved_to": self.object.resolved_to.all(),
213+
"vulnerable_to": self.object.vulnerable_to.all(),
218214
}
219215
)
220216
return context

0 commit comments

Comments
 (0)