Skip to content

Commit 89479c9

Browse files
committed
optim: do not fetch paste content on /d/ req
1 parent 8731e10 commit 89479c9

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/handlers/handleRead.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export async function handleGet(request: Request, env: Env, ctx: ExecutionContex
113113

114114
// when not isHead, always need to get paste unless "m"
115115
// when isHead, no need to get paste unless "u"
116-
const shouldGetPasteContent = (!isHead && role !== "m") || (isHead && role === "u")
116+
const shouldGetPasteContent = (!isHead && role !== "m" && role !== "d") || (isHead && role === "u")
117117

118118
const item: PasteWithMetadata | null = shouldGetPasteContent
119119
? await getPaste(env, nameFromPath, ctx)
@@ -124,9 +124,6 @@ export async function handleGet(request: Request, env: Env, ctx: ExecutionContex
124124
throw new WorkerError(404, `paste of name '${nameFromPath}' not found`)
125125
}
126126

127-
// check `if-modified-since`
128-
const pasteLastModifiedUnix = item.metadata.lastModifiedAtUnix
129-
130127
let inferred_mime =
131128
url.searchParams.get("mime") ||
132129
(ext && mime.getType(ext)) ||
@@ -138,6 +135,8 @@ export async function handleGet(request: Request, env: Env, ctx: ExecutionContex
138135
inferred_mime = "text/plain;charset=UTF-8"
139136
}
140137

138+
// check `if-modified-since`
139+
const pasteLastModifiedUnix = item.metadata.lastModifiedAtUnix
141140
const headerModifiedSince = request.headers.get("If-Modified-Since")
142141
if (headerModifiedSince) {
143142
const headerModifiedSinceUnix = Date.parse(headerModifiedSince) / 1000
@@ -207,7 +206,7 @@ export async function handleGet(request: Request, env: Env, ctx: ExecutionContex
207206
"{{PASTE_NAME}}",
208207
nameFromPath + (filename ? "/" + filename : ext ? ext : ""),
209208
)
210-
return new Response(shouldGetPasteContent ? page : null, {
209+
return new Response(isHead ? null : page, {
211210
headers: {
212211
"Content-Type": `text/html;charset=UTF-8`,
213212
...pasteCacheHeader(env),

0 commit comments

Comments
 (0)