Speed up async_render_with_possible_json_value (#118080)

This commit is contained in:
J. Nick Koston 2024-05-24 17:43:42 -10:00 committed by GitHub
parent 3416162fdb
commit 5cb3bc19c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,7 +7,7 @@ import asyncio
import base64
import collections.abc
from collections.abc import Callable, Generator, Iterable
from contextlib import AbstractContextManager, suppress
from contextlib import AbstractContextManager
from contextvars import ContextVar
from datetime import date, datetime, time, timedelta
from functools import cache, lru_cache, partial, wraps
@ -759,8 +759,10 @@ class Template:
variables = dict(variables or {})
variables["value"] = value
with suppress(*JSON_DECODE_EXCEPTIONS):
try: # noqa: SIM105 - suppress is much slower
variables["value_json"] = json_loads(value)
except JSON_DECODE_EXCEPTIONS:
pass
try:
render_result = _render_with_context(