From d8d476463b97bc322ca82851371259bb0e2fb3cb Mon Sep 17 00:00:00 2001 From: Satish Gandham Date: Mon, 8 Jul 2024 15:26:52 +0530 Subject: [PATCH 1/3] [WEB-1728] Chore: Preload apis required to bootstrap the application (#5026) * chore: prefetch apis * chore: implemented cache-control * Preload links with credentials * chore: updated time in the cache and handled it based on cookie * chore: make cache private --------- Co-authored-by: gurusainath --- apiserver/plane/app/views/user/base.py | 9 +++++++++ apiserver/plane/app/views/workspace/base.py | 5 +++++ apiserver/plane/license/api/views/instance.py | 3 +++ web/app/layout.tsx | 13 +++++++++++++ 4 files changed, 30 insertions(+) diff --git a/apiserver/plane/app/views/user/base.py b/apiserver/plane/app/views/user/base.py index ac0c3d711f..96e042a16a 100644 --- a/apiserver/plane/app/views/user/base.py +++ b/apiserver/plane/app/views/user/base.py @@ -37,6 +37,9 @@ from plane.utils.paginator import BasePaginator from plane.authentication.utils.host import user_ip from plane.bgtasks.user_deactivation_email_task import user_deactivation_email from plane.utils.host import base_host +from django.utils.decorators import method_decorator +from django.views.decorators.cache import cache_control +from django.views.decorators.vary import vary_on_cookie class UserEndpoint(BaseViewSet): @@ -47,6 +50,8 @@ class UserEndpoint(BaseViewSet): return self.request.user @cache_response(60 * 60) + @method_decorator(cache_control(private=True, max_age=12)) + @method_decorator(vary_on_cookie) def retrieve(self, request): serialized_data = UserMeSerializer(request.user).data return Response( @@ -55,6 +60,8 @@ class UserEndpoint(BaseViewSet): ) @cache_response(60 * 60) + @method_decorator(cache_control(private=True, max_age=12)) + @method_decorator(vary_on_cookie) def retrieve_user_settings(self, request): serialized_data = UserMeSettingsSerializer(request.user).data return Response(serialized_data, status=status.HTTP_200_OK) @@ -288,6 +295,8 @@ class AccountEndpoint(BaseAPIView): class ProfileEndpoint(BaseAPIView): + @method_decorator(cache_control(private=True, max_age=12)) + @method_decorator(vary_on_cookie) def get(self, request): profile = Profile.objects.get(user=request.user) serializer = ProfileSerializer(profile) diff --git a/apiserver/plane/app/views/workspace/base.py b/apiserver/plane/app/views/workspace/base.py index afe9985806..6fa0ccc1eb 100644 --- a/apiserver/plane/app/views/workspace/base.py +++ b/apiserver/plane/app/views/workspace/base.py @@ -44,6 +44,9 @@ from plane.db.models import ( WorkspaceTheme, ) from plane.utils.cache import cache_response, invalidate_cache +from django.utils.decorators import method_decorator +from django.views.decorators.cache import cache_control +from django.views.decorators.vary import vary_on_cookie from plane.utils.constants import RESTRICTED_WORKSPACE_SLUGS @@ -172,6 +175,8 @@ class UserWorkSpacesEndpoint(BaseAPIView): ] @cache_response(60 * 60 * 2) + @method_decorator(cache_control(private=True, max_age=12)) + @method_decorator(vary_on_cookie) def get(self, request): fields = [ field diff --git a/apiserver/plane/license/api/views/instance.py b/apiserver/plane/license/api/views/instance.py index 8d885083ae..4f021963b5 100644 --- a/apiserver/plane/license/api/views/instance.py +++ b/apiserver/plane/license/api/views/instance.py @@ -23,6 +23,8 @@ from plane.license.utils.instance_value import ( get_configuration_value, ) from plane.utils.cache import cache_response, invalidate_cache +from django.utils.decorators import method_decorator +from django.views.decorators.cache import cache_control class InstanceEndpoint(BaseAPIView): @@ -36,6 +38,7 @@ class InstanceEndpoint(BaseAPIView): ] @cache_response(60 * 60 * 2, user=False) + @method_decorator(cache_control(private=True, max_age=12)) def get(self, request): instance = Instance.objects.first() diff --git a/web/app/layout.tsx b/web/app/layout.tsx index 231f4da2fa..4647a099be 100644 --- a/web/app/layout.tsx +++ b/web/app/layout.tsx @@ -5,6 +5,8 @@ import "@/styles/globals.css"; import "@/styles/command-pallette.css"; import "@/styles/emoji.css"; import "@/styles/react-day-picker.css"; +// helpers +import { API_BASE_URL } from "@/helpers/common.helper"; // local import { AppProvider } from "./provider"; @@ -36,6 +38,17 @@ export default function RootLayout({ children }: { children: React.ReactNode }) + {/* preloading */} + + + + +
From 1cd55cd95b5abf421e9df1bcc217d34747d3fd41 Mon Sep 17 00:00:00 2001 From: Nikhil <118773738+pablohashescobar@users.noreply.github.com> Date: Mon, 8 Jul 2024 15:27:45 +0530 Subject: [PATCH 2/3] fix: remove user workspace cache on account deactivation (#5065) --- apiserver/plane/app/views/user/base.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apiserver/plane/app/views/user/base.py b/apiserver/plane/app/views/user/base.py index 96e042a16a..27bfd3b7a6 100644 --- a/apiserver/plane/app/views/user/base.py +++ b/apiserver/plane/app/views/user/base.py @@ -86,6 +86,9 @@ class UserEndpoint(BaseViewSet): return super().partial_update(request, *args, **kwargs) @invalidate_cache(path="/api/users/me/") + @invalidate_cache( + path="/api/users/me/workspaces/", multiple=True, user=False + ) def deactivate(self, request): # Check all workspace user is active user = self.get_object() From 4e815c0fed7640a8cbda8a5963b542b3b8208e89 Mon Sep 17 00:00:00 2001 From: Anmol Singh Bhatia <121005188+anmolsinghbhatia@users.noreply.github.com> Date: Mon, 8 Jul 2024 15:28:38 +0530 Subject: [PATCH 3/3] fix: issue link error toast alert (#5068) --- .../components/issues/issue-detail-widgets/links/helper.tsx | 4 ++-- web/core/components/issues/issue-detail/links/root.tsx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/web/core/components/issues/issue-detail-widgets/links/helper.tsx b/web/core/components/issues/issue-detail-widgets/links/helper.tsx index 48370d04cb..f0a6ed3163 100644 --- a/web/core/components/issues/issue-detail-widgets/links/helper.tsx +++ b/web/core/components/issues/issue-detail-widgets/links/helper.tsx @@ -21,9 +21,9 @@ export const useLinkOperations = (workspaceSlug: string, projectId: string, issu type: TOAST_TYPE.SUCCESS, title: "Link created", }); - } catch (error) { + } catch (error: any) { setToast({ - message: "The link could not be created", + message: error?.data?.error ?? "The link could not be created", type: TOAST_TYPE.ERROR, title: "Link not created", }); diff --git a/web/core/components/issues/issue-detail/links/root.tsx b/web/core/components/issues/issue-detail/links/root.tsx index e50244fd43..1450bb4ce0 100644 --- a/web/core/components/issues/issue-detail/links/root.tsx +++ b/web/core/components/issues/issue-detail/links/root.tsx @@ -52,9 +52,9 @@ export const IssueLinkRoot: FC = (props) => { title: "Link created", }); toggleIssueLinkModal(false); - } catch (error) { + } catch (error: any) { setToast({ - message: "The link could not be created", + message: error?.data?.error ?? "The link could not be created", type: TOAST_TYPE.ERROR, title: "Link not created", });