Skip to content

Commit 613a08c

Browse files
authored
Allow /api/scratch/ABCDE to be cached for 1s (#1773)
* Allow /api/scratch/ABCDE to be cached for 1s * Update user status on public endpoints * Don't prefetch /new, /platform and /preset on homepage
1 parent bb19ab0 commit 613a08c

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

backend/coreapp/middleware.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def is_public_request(req: Request) -> bool:
4949
("GET", "/api/preset"),
5050
("GET", "/api/scratch-count$"),
5151
("GET", "/api/scratch/[A-Za-z0-9]+/compile$"),
52+
("GET", "/api/scratch/[A-Za-z0-9]+/export$"),
53+
("GET", "/api/scratch/[A-Za-z0-9]+/family$"),
5254
("GET", "/api/scratch/[A-Za-z0-9]+$"),
5355
("GET", "/api/scratch$"),
5456
("GET", "/api/search$"),
@@ -87,11 +89,6 @@ def middleware(request: Request) -> Response:
8789
request.profile = Profile()
8890
return get_response(request)
8991

90-
# Avoid creating persistent for public endpoints
91-
if is_public_request(request):
92-
request.profile = Profile()
93-
return get_response(request)
94-
9592
profile = None
9693

9794
# Try user-linked profile
@@ -109,6 +106,11 @@ def middleware(request: Request) -> Response:
109106
if profile and profile.user and request.user.is_anonymous:
110107
request.user = profile.user
111108

109+
# Avoid creating persistent for public endpoints
110+
if not profile and is_public_request(request):
111+
request.profile = Profile()
112+
return get_response(request)
113+
112114
# Create new profile if none found
113115
if not profile:
114116
profile = Profile(

backend/coreapp/views/scratch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ class ScratchPagination(CursorPagination):
268268

269269

270270
@method_decorator(globally_cacheable(max_age=5, stale_while_revalidate=1), name="list")
271+
@method_decorator(globally_cacheable(max_age=1), name="retrieve")
271272
class ScratchViewSet(
272273
mixins.CreateModelMixin,
273274
mixins.DestroyModelMixin,

frontend/src/app/(navfooter)/WelcomeInfo.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default async function WelcomeInfo() {
4646
{SITE_DESCRIPTION}
4747
</p>
4848
<div className="flex flex-col items-center justify-center gap-2 md:flex-row">
49-
<Link href="/new">
49+
<Link href="/new" prefetch={false}>
5050
<Button primary>
5151
Start decomping
5252
<ArrowRightIcon />
@@ -56,11 +56,15 @@ export default async function WelcomeInfo() {
5656
</div>
5757
<p className="mx-auto my-6 w-full max-w-screen-sm text-gray-11 text-sm leading-tight">
5858
Alternatively, check out existing scratches filtered by{" "}
59-
<Link className="font-bold" href="/platform">
59+
<Link
60+
className="font-bold"
61+
href="/platform"
62+
prefetch={false}
63+
>
6064
platform
6165
</Link>{" "}
6266
or{" "}
63-
<Link className="font-bold" href="/preset">
67+
<Link className="font-bold" href="/preset" prefetch={false}>
6468
preset
6569
</Link>
6670
.

0 commit comments

Comments
 (0)