Skip to content

Commit e862fe1

Browse files
fix: make sure we only create the wrapper once at decoration time
Previously we were doing redundant work on each call when this could be fixed a decoration time with no functional difference
1 parent 0f9448b commit e862fe1

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/firebase_functions/https_fn.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -432,14 +432,19 @@ def example(request: Request) -> Response:
432432
options = HttpsOptions(**kwargs)
433433

434434
def on_request_inner_decorator(func: _C1):
435+
func_with_init = _core._with_init(func)
436+
437+
if options.cors is not None:
438+
wrapped_function = _cross_origin(
439+
methods=options.cors.cors_methods,
440+
origins=options.cors.cors_origins,
441+
)(func_with_init)
442+
else:
443+
wrapped_function = func_with_init
444+
435445
@_functools.wraps(func)
436446
def on_request_wrapped(request: Request) -> Response:
437-
if options.cors is not None:
438-
return _cross_origin(
439-
methods=options.cors.cors_methods,
440-
origins=options.cors.cors_origins,
441-
)(_core._with_init(func))(request)
442-
return _core._with_init(func)(request)
447+
return wrapped_function(request)
443448

444449
_util.set_func_endpoint_attr(
445450
on_request_wrapped,

0 commit comments

Comments
 (0)