|
11 | 11 | from urllib.parse import urlencode |
12 | 12 |
|
13 | 13 | from django.contrib.postgres.aggregates import ArrayAgg |
| 14 | +from django.core.cache import cache |
14 | 15 | from django.db.models import Exists |
15 | 16 | from django.db.models import F |
16 | 17 | from django.db.models import Max |
|
22 | 23 | from packageurl import PackageURL |
23 | 24 | from rest_framework import serializers |
24 | 25 | from rest_framework import viewsets |
| 26 | +from rest_framework.response import Response |
25 | 27 | from rest_framework.reverse import reverse |
26 | 28 | from rest_framework.throttling import AnonRateThrottle |
| 29 | +from rest_framework.viewsets import ViewSet |
27 | 30 |
|
28 | 31 | from vulnerabilities.models import SSVC |
29 | 32 | from vulnerabilities.models import AdvisoryAlias |
@@ -336,6 +339,20 @@ def create(self, request, *args, **kwargs): |
336 | 339 | return self.get_paginated_response(serializer.data) |
337 | 340 |
|
338 | 341 |
|
| 342 | +class PackageTypesView(ViewSet): |
| 343 | + def list(self, request): |
| 344 | + types = cache.get("package_types") |
| 345 | + |
| 346 | + if types is None: |
| 347 | + types = list( |
| 348 | + PackageV2.objects.values_list("type", flat=True).distinct().order_by("type") |
| 349 | + ) |
| 350 | + |
| 351 | + cache.set("package_types", types, 60 * 60) |
| 352 | + |
| 353 | + return Response(types) |
| 354 | + |
| 355 | + |
339 | 356 | class AffectedByAdvisoryV3Serializer(AdvisoryV3Serializer): |
340 | 357 | fixed_by_packages = serializers.SerializerMethodField() |
341 | 358 | advisory_uid = serializers.CharField(source="avid", read_only=True) |
|
0 commit comments