Skip to content

Commit 6742ba6

Browse files
committed
feat: cache computed load factor for 5 minutes
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent 4240d36 commit 6742ba6

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

vulnerabilities/views.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from cvss.exceptions import CVSS4MalformedError
1616
from django.contrib import messages
1717
from django.contrib.auth.views import LoginView
18+
from django.core.cache import cache
1819
from django.core.exceptions import ValidationError
1920
from django.core.mail import send_mail
2021
from django.db.models import Exists
@@ -48,6 +49,7 @@
4849
from vulnerabilities.pipelines.v2_importers.epss_importer_v2 import EPSSImporterPipeline
4950
from vulnerabilities.severity_systems import EPSS
5051
from vulnerabilities.severity_systems import SCORING_SYSTEMS
52+
from vulnerabilities.tasks import compute_queue_load_factor
5153
from vulnerabilities.throttling import AnonUserUIThrottle
5254
from vulnerabilities.utils import TYPES_WITH_MULTIPLE_IMPORTERS
5355
from vulnerabilities.utils import get_advisories_from_groups
@@ -57,6 +59,8 @@
5759

5860
PAGE_SIZE = 10
5961

62+
CACHE_TIMEOUT = 60 * 5
63+
6064

6165
class VulnerableCodeView(View):
6266
"""
@@ -961,6 +965,13 @@ def get_queryset(self):
961965

962966
def get_context_data(self, **kwargs):
963967
context = super().get_context_data(**kwargs)
968+
load_per_queue = cache.get("load_per_queue")
969+
970+
if load_per_queue is None:
971+
load_per_queue = compute_queue_load_factor()
972+
cache.set("load_per_queue", load_per_queue, CACHE_TIMEOUT)
973+
974+
context["load_per_queue"] = load_per_queue
964975
context["active_pipeline_count"] = PipelineSchedule.objects.filter(is_active=True).count()
965976
context["disabled_pipeline_count"] = PipelineSchedule.objects.filter(
966977
is_active=False

0 commit comments

Comments
 (0)