Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/titiler/core/titiler/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,27 @@ def get_dependency_query_params(

Important: We assume the `callable` in not a co-routine.
"""
dep = get_dependant(path="", call=dependency)
# Avoid recreating Dependant for each call if possible
dep = get_dependant.__globals__.get("_codeflash_dep_cache", {}).get(id(dependency)) # type: ignore
if dep is None:
dep = get_dependant(path="", call=dependency)
_cache = get_dependant.__globals__.setdefault("_codeflash_dep_cache", {})
_cache[id(dependency)] = dep

# Fast path for QueryParams
if isinstance(params, QueryParams):
qp = params
else:
# Avoid unnecessary urlencode when params is empty or already a QueryParams
if not params:
qp = QueryParams("")
else:
# Faster than urlencode for small dicts: prebuild string when no lists in values are present
if all(not isinstance(v, (list, tuple)) for v in params.values()):
qp = QueryParams('&'.join(f"{k}={v}" for k, v in params.items()))
else:
qp = QueryParams(urlencode(params, doseq=True))

qp = (
QueryParams(urlencode(params, doseq=True))
if isinstance(params, Dict)
else params
)
return request_params_to_args(dep.query_params, qp)


Expand Down