From 07d6e2f6605d9fc731422d508178ceaf09ab6589 Mon Sep 17 00:00:00 2001 From: kshitijrajsharma Date: Sat, 19 Oct 2024 09:48:05 +0200 Subject: [PATCH 1/3] Adds cache on workspaceview , removes pagination on banner endpoint , bypass request for training accuracy graph --- backend/core/views.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/backend/core/views.py b/backend/core/views.py index c8d9c168..10667f4c 100644 --- a/backend/core/views.py +++ b/backend/core/views.py @@ -781,6 +781,8 @@ def get(self, request, feedback_aoi_id: int): class TrainingWorkspaceView(APIView): + @method_decorator(cache_page(60 * 15)) + # @method_decorator(vary_on_headers("access-token")) def get(self, request, lookup_dir=None): """List out status of training workspace : size in bytes""" # {workspace_dir:{file_name:{size:20,type:file},dir_name:{size:20,len:4,type:dir}}} @@ -814,6 +816,15 @@ class TrainingWorkspaceDownloadView(APIView): authentication_classes = [OsmAuthentication] permission_classes = [IsOsmAuthenticated] + def dispatch(self, request, *args, **kwargs): + lookup_dir = kwargs.get("lookup_dir") + if lookup_dir.endswith("training_validation_sparse_categorical_accuracy.png"): + # bypass + self.authentication_classes = [] + self.permission_classes = [] + + return super().dispatch(request, *args, **kwargs) + def get(self, request, lookup_dir): base_dir = os.path.join(settings.TRAINING_WORKSPACE, lookup_dir) if not os.path.exists(base_dir): @@ -860,6 +871,7 @@ class BannerViewSet(viewsets.ModelViewSet): authentication_classes = [OsmAuthentication] permission_classes = [IsAdminUser, IsStaffUser] public_methods = ["GET"] + pagination_class = None def get_queryset(self): now = timezone.now() @@ -869,7 +881,7 @@ def get_queryset(self): @cache_page(60 * 15) ## Cache for 15 mins -# @vary_on_cookie , if you wanna do user specific cache +# @vary_on_cookie @api_view(["GET"]) def get_kpi_stats(request): total_models_with_status_published = Model.objects.filter(status=0).count() From 2e683d98ecacecae176bebf47261bae5fe71861e Mon Sep 17 00:00:00 2001 From: kshitijrajsharma Date: Sat, 19 Oct 2024 10:04:54 +0200 Subject: [PATCH 2/3] Disable global workspace endpoint and added lookup dir as compulsary to reduce lookup --- backend/core/urls.py | 2 +- backend/core/views.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/core/urls.py b/backend/core/urls.py index 9a236206..7508752d 100644 --- a/backend/core/urls.py +++ b/backend/core/urls.py @@ -69,7 +69,7 @@ path( "feedback-aoi/gpx//", GenerateFeedbackAOIGpxView.as_view() ), - path("workspace/", TrainingWorkspaceView.as_view()), + # path("workspace/", TrainingWorkspaceView.as_view()), path( "workspace/download//", TrainingWorkspaceDownloadView.as_view() ), diff --git a/backend/core/views.py b/backend/core/views.py index 10667f4c..044bc708 100644 --- a/backend/core/views.py +++ b/backend/core/views.py @@ -783,7 +783,7 @@ def get(self, request, feedback_aoi_id: int): class TrainingWorkspaceView(APIView): @method_decorator(cache_page(60 * 15)) # @method_decorator(vary_on_headers("access-token")) - def get(self, request, lookup_dir=None): + def get(self, request, lookup_dir): """List out status of training workspace : size in bytes""" # {workspace_dir:{file_name:{size:20,type:file},dir_name:{size:20,len:4,type:dir}}} base_dir = settings.TRAINING_WORKSPACE From 5bb70748b37359092eaf59a7583946312cb5654e Mon Sep 17 00:00:00 2001 From: kshitijrajsharma Date: Sat, 19 Oct 2024 10:09:43 +0200 Subject: [PATCH 3/3] Add documentation for the workspace endpoint --- backend/core/views.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/backend/core/views.py b/backend/core/views.py index 044bc708..8bbd2d35 100644 --- a/backend/core/views.py +++ b/backend/core/views.py @@ -784,7 +784,18 @@ class TrainingWorkspaceView(APIView): @method_decorator(cache_page(60 * 15)) # @method_decorator(vary_on_headers("access-token")) def get(self, request, lookup_dir): - """List out status of training workspace : size in bytes""" + """ + List the status of the training workspace. + + ### Returns: + - **Size**: The total size of the workspace in bytes. + - **dir/file**: The current dir/file on the lookup_dir. + + ### Workspace Structure: + By default, the training workspace is organized as follows: + - Training files are stored in the directory: `dataset{dataset_id}/output/training_{training}` + """ + # {workspace_dir:{file_name:{size:20,type:file},dir_name:{size:20,len:4,type:dir}}} base_dir = settings.TRAINING_WORKSPACE if lookup_dir: