Skip to content

Commit 90d41ec

Browse files
committed
avoid compiling regex on each call
1 parent 4e9cc05 commit 90d41ec

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

gapic/templates/%namespace/%name_%version/%sub/services/%service/_client_macros.j2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@
149149
{% if not method.client_streaming %}
150150
{% for routing_param in method.routing_rule.routing_parameters %}
151151
{% if routing_param.path_template %} {# Need to match. #}
152-
153-
routing_param_regex = {{ routing_param.to_regex() }}
154-
regex_match = routing_param_regex.match(request.{{ routing_param.field }})
152+
if getattr( {{ name }}, 'routing_param_regex', None) is None:
153+
{{ name }}.routing_param_regex = {{ routing_param.to_regex() }}
154+
regex_match = {{name}}.routing_param_regex.match(request.{{ routing_param.field }})
155155
if regex_match and regex_match.group("{{ routing_param.key }}"):
156156
header_params["{{ routing_param.key }}"] = regex_match.group("{{ routing_param.key }}")
157157

0 commit comments

Comments
 (0)