Skip to content

Commit

Permalink
[WEB-1728] Chore: Preload apis required to bootstrap the application (m…
Browse files Browse the repository at this point in the history
…akeplane#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 <gurusainath007@gmail.com>
  • Loading branch information
SatishGandham and gurusainath authored Jul 8, 2024
1 parent fc2585b commit d8d4764
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions apiserver/plane/app/views/user/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
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):
Expand All @@ -47,6 +50,8 @@ def get_object(self):
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(
Expand All @@ -55,6 +60,8 @@ def retrieve(self, request):
)

@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)
Expand Down Expand Up @@ -288,6 +295,8 @@ def delete(self, request, pk):


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)
Expand Down
5 changes: 5 additions & 0 deletions apiserver/plane/app/views/workspace/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
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


Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions apiserver/plane/license/api/views/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
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):
Expand All @@ -36,6 +38,7 @@ def get_permissions(self):
]

@cache_response(60 * 60 * 2, user=False)
@method_decorator(cache_control(private=True, max_age=12))
def get(self, request):
instance = Instance.objects.first()

Expand Down
13 changes: 13 additions & 0 deletions web/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -36,6 +38,17 @@ export default function RootLayout({ children }: { children: React.ReactNode })
<link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png" />
<link rel="manifest" href="/site.webmanifest.json" />
<link rel="shortcut icon" href="/favicon/favicon.ico" />
{/* preloading */}
<link rel="preload" href={`${API_BASE_URL}/api/instances/`} as="fetch" crossOrigin="use-credentials" />
<link rel="preload" href={`${API_BASE_URL}/api/users/me/ `} as="fetch" crossOrigin="use-credentials" />
<link rel="preload" href={`${API_BASE_URL}/api/users/me/profile/ `} as="fetch" crossOrigin="use-credentials" />
<link rel="preload" href={`${API_BASE_URL}/api/users/me/settings/ `} as="fetch" crossOrigin="use-credentials" />
<link
rel="preload"
href={`${API_BASE_URL}/api/users/me/workspaces/`}
as="fetch"
crossOrigin="use-credentials"
/>
</head>
<body>
<div id="context-menu-portal" />
Expand Down

0 comments on commit d8d4764

Please sign in to comment.