Skip to content

Commit

Permalink
Run the debugger to fix the performance issue ( run this commit after…
Browse files Browse the repository at this point in the history
… enable debug toolbar )

Signed-off-by: ziadhany <[email protected]>
  • Loading branch information
ziadhany committed Apr 9, 2024
1 parent e99e35f commit 02897f8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
16 changes: 8 additions & 8 deletions vulnerabilities/management/commands/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ def handle(self, *args, **options):

self.stdout.write(self.style.SUCCESS("Successfully exported vulnerablecode data"))

def export_data(self, git_path):
@staticmethod
def export_data(git_path):
"""
export vulnerablecode data
by running `python manage.py export /path/vulnerablecode-data`
"""
self.stdout.write("Exporting vulnerablecode data")
# self.stdout.write("Exporting vulnerablecode data")

ecosystems = [pkg.type for pkg in Package.objects.distinct("type")]

Expand All @@ -51,8 +52,7 @@ def export_data(self, git_path):
vul_files = {} # {"vulnerability path": "data" }

for purl in (
Package.objects.filter(type=ecosystem)
.prefetch_related("vulnerabilities")
Package.objects.prefetch_related("vulnerabilities").filter(type=ecosystem)[0:10]
.paginated()
):
purl_without_version = PackageURL(
Expand Down Expand Up @@ -101,11 +101,11 @@ def export_data(self, git_path):
],
}

for items in [package_files, vul_files]:
for filepath, data in items.items():
create_file(filepath, git_path, data)
# for items in [package_files, vul_files]:
# for filepath, data in items.items():
# create_file(filepath, git_path, data)

self.stdout.write(f"Successfully exported {ecosystem} data")
# self.stdout.write(f"Successfully exported {ecosystem} data")


def create_file(filepath, git_path, data):
Expand Down
10 changes: 10 additions & 0 deletions vulnerabilities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
#
import logging
from datetime import datetime
from pathlib import Path

from cvss.exceptions import CVSS2MalformedError
from cvss.exceptions import CVSS3MalformedError
from django.contrib import messages
from django.core.exceptions import ValidationError
from django.core.mail import send_mail
from django.http.response import Http404
from django.http.response import HttpResponse
from django.shortcuts import redirect
from django.shortcuts import render
from django.urls import reverse_lazy
Expand All @@ -27,6 +29,8 @@
from vulnerabilities.forms import ApiUserCreationForm
from vulnerabilities.forms import PackageSearchForm
from vulnerabilities.forms import VulnerabilitySearchForm
from vulnerabilities.management.commands import export
from vulnerabilities.management.commands.export import Command
from vulnerabilities.models import VulnerabilityStatusType
from vulnerabilities.severity_systems import SCORING_SYSTEMS
from vulnerabilities.utils import get_severity_range
Expand Down Expand Up @@ -233,3 +237,9 @@ def form_valid(self, form):

def get_success_url(self):
return reverse_lazy("api_user_request")


def fake_view(request, *args, **kwargs):
git_path = Path("/home/ziad/vulnerablecode-data")
Command.export_data(git_path)
return render(request=request, template_name="index.html")
5 changes: 5 additions & 0 deletions vulnerablecode/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from vulnerabilities.views import PackageSearch
from vulnerabilities.views import VulnerabilityDetails
from vulnerabilities.views import VulnerabilitySearch
from vulnerabilities.views import fake_view
from vulnerablecode.settings import DEBUG_TOOLBAR


Expand Down Expand Up @@ -102,6 +103,10 @@ def __init__(self, *args, **kwargs):
"admin/",
admin.site.urls,
),
path(
"fake_view",
fake_view,
),
]

if DEBUG_TOOLBAR:
Expand Down

0 comments on commit 02897f8

Please sign in to comment.