Skip to content

Commit 31ddf10

Browse files
committed
Address review comments
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent 44248b5 commit 31ddf10

4 files changed

Lines changed: 38 additions & 14 deletions

File tree

vulnerabilities/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def bulk_search(self, request):
247247
data={"Error": "A non-empty 'purls' list of PURLs is required."},
248248
)
249249

250-
query = Package.objects.filter(package__in=purls)
250+
query = Package.objects.filter(package_url__in=purls)
251251

252252
if not purl_only:
253253
return Response(
@@ -264,8 +264,8 @@ def all(self, request):
264264
"""
265265
Return the Package URLs of all packages known to be vulnerable.
266266
"""
267-
vulnerable_packages = Package.objects.vulnerable().only(*PackageURL._fields).distinct()
268-
vulnerable_purls = [str(package.purl) for package in vulnerable_packages]
267+
vulnerable_packages = Package.objects.vulnerable().only("package_url").distinct()
268+
vulnerable_purls = [str(package.package_url) for package in vulnerable_packages]
269269
return Response(vulnerable_purls)
270270

271271

vulnerabilities/migrations/0034_package_package.py renamed to vulnerabilities/migrations/0034_package_package_url.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by Django 4.0.7 on 2022-11-25 12:57
1+
# Generated by Django 4.0.7 on 2022-11-25 17:28
22

33
from django.db import migrations, models
44

@@ -12,7 +12,7 @@ class Migration(migrations.Migration):
1212
operations = [
1313
migrations.AddField(
1414
model_name='package',
15-
name='package',
16-
field=models.CharField(blank=True, help_text='The Package URL for this package.', max_length=255),
15+
name='package_url',
16+
field=models.CharField(blank=True, db_index=True, help_text='The Package URL for this package.', max_length=255),
1717
),
1818
]

vulnerabilities/migrations/0035_auto_20221125_1257.py renamed to vulnerabilities/migrations/0035_add_package_url_to_packages.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
# Generated by Django 4.0.7 on 2022-11-25 12:57
2-
31
from django.db import migrations
42
from packageurl import PackageURL
53

64
class Migration(migrations.Migration):
75

8-
def save_package(apps, schema_editor):
6+
def save_purls(apps, schema_editor):
97
Package = apps.get_model("vulnerabilities", "Package")
8+
updatables = []
109
for package in Package.objects.all():
1110
purl = PackageURL(
1211
type=package.type,
@@ -16,13 +15,20 @@ def save_package(apps, schema_editor):
1615
qualifiers=package.qualifiers,
1716
subpath=package.subpath,
1817
)
19-
package.package = str(purl)
20-
package.save()
18+
package.package_url = str(purl)
19+
updatables.append(package)
20+
21+
updated = Package.objects.bulk_update(
22+
objs = updatables,
23+
fields=["package_url"],
24+
batch_size=500,
25+
)
26+
print(f"Migrated {updated} packages with package_url")
2127

2228
dependencies = [
23-
('vulnerabilities', '0034_package_package'),
29+
('vulnerabilities', '0034_package_package_url'),
2430
]
2531

2632
operations = [
27-
migrations.RunPython(save_package, reverse_code=migrations.RunPython.noop),
28-
]
33+
migrations.RunPython(save_purls, reverse_code=migrations.RunPython.noop),
34+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 4.0.7 on 2022-11-25 17:34
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('vulnerabilities', '0035_add_package_url_to_packages'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='package',
15+
name='package_url',
16+
field=models.CharField(db_index=True, help_text='The Package URL for this package.', max_length=255),
17+
),
18+
]

0 commit comments

Comments
 (0)