fix: remove unnecessary URL allocation (#2554)

This commit is contained in:
Marvin Hagemeister
2024-06-27 12:34:56 +02:00
committed by GitHub
parent bfb5753ecb
commit 138d4c457c
4 changed files with 5 additions and 3 deletions
+1
View File
@@ -203,6 +203,7 @@ export class App<State> {
const { params, handlers } = matched; const { params, handlers } = matched;
const ctx = new FreshReqContext<State>( const ctx = new FreshReqContext<State>(
req, req,
url,
conn, conn,
params, params,
this.config, this.config,
+2 -1
View File
@@ -111,6 +111,7 @@ export class FreshReqContext<State>
constructor( constructor(
req: Request, req: Request,
url: URL,
info: Deno.ServeHandlerInfo | Deno.ServeUnixHandlerInfo, info: Deno.ServeHandlerInfo | Deno.ServeUnixHandlerInfo,
params: Record<string, string>, params: Record<string, string>,
config: ResolvedFreshConfig, config: ResolvedFreshConfig,
@@ -118,7 +119,7 @@ export class FreshReqContext<State>
islandRegistry: ServerIslandRegistry, islandRegistry: ServerIslandRegistry,
buildCache: BuildCache, buildCache: BuildCache,
) { ) {
this.url = new URL(req.url); this.url = url;
this.req = req; this.req = req;
this.info = info; this.info = info;
this.params = params; this.params = params;
+1
View File
@@ -78,6 +78,7 @@ export function serveMiddleware<T>(
const ctx = new FreshReqContext<T>( const ctx = new FreshReqContext<T>(
req, req,
new URL(req.url),
DEFAULT_CONN_INFO, DEFAULT_CONN_INFO,
{}, {},
config, config,
+1 -2
View File
@@ -5,8 +5,7 @@ import { define } from "../utils/state.ts";
export const handler = define.handlers({ export const handler = define.handlers({
GET(ctx) { GET(ctx) {
const url = new URL(ctx.req.url); const search = new URLSearchParams(ctx.url.search);
const search = new URLSearchParams(url.search);
const vote = search.get("vote"); const vote = search.get("vote");
return page({ vote }); return page({ vote });
}, },