Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
Feat.: optimizized Database Access for ConfirmedUpload File
Browse files Browse the repository at this point in the history
  • Loading branch information
MeisterSeSe committed Oct 13, 2023
1 parent 1ab6a2d commit 526ef9e
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions backend/core/fileupload/viewsets.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from django.db.models import Q

from core.fileupload.models import Family, Tag, License, File, Analysis, AnalysisResult
from core.fileupload.utils import generate_random_string
from core.fileupload.serializers import (
Expand Down Expand Up @@ -383,17 +385,18 @@ def list(self, request, **kwargs):
indicating if the user which has sent the request is the owner.
"""
queryset = File.objects.filter(is_confirmed=True)
familyId = self.request.query_params.get("family")
if familyId is not None:
queryset = queryset.filter(family__id=familyId).order_by("version")
family_id = self.request.query_params.get("family")
owner = self.request.query_params.get("owner")

filter_conditions = Q(is_confirmed=True)
if family_id is not None:
filter_conditions &= Q(family__id=family_id)
if owner is not None:
queryset = queryset.filter(owner=owner)
files = FilesSerializer(queryset, many=True).data
anonymized_files = []
for file in files:
anonymized_file = anonymize_file(file, request)
anonymized_files.append(anonymized_file)
filter_conditions &= Q(owner=owner)
queryset = (queryset.filter(filter_conditions).select_related('family', 'license').
prefetch_related('tags').order_by("version"))

anonymized_files = [anonymize_file(FilesSerializer(file).data, request) for file in queryset]
return Response(anonymized_files)

def retrieve(self, request, *args, **kwargs):
Expand Down

0 comments on commit 526ef9e

Please sign in to comment.