Skip to content

Commit

Permalink
Only initialize mako TemplateLookup once
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyWong16 committed Jun 27, 2023
1 parent 2a48e33 commit d9b3b31
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions plexpy/webserve.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,16 @@
from plexpy import macos


def serve_template(templatename, **kwargs):
interface_dir = os.path.join(str(plexpy.PROG_DIR), 'data/interfaces/')
template_dir = os.path.join(str(interface_dir), plexpy.CONFIG.INTERFACE)
TEMPLATE_LOOKUP = None

_hplookup = TemplateLookup(directories=[template_dir], default_filters=['unicode', 'h'],
error_handler=mako_error_handler)

def serve_template(template_name, **kwargs):
global TEMPLATE_LOOKUP
if TEMPLATE_LOOKUP is None:
interface_dir = os.path.join(str(plexpy.PROG_DIR), 'data/interfaces/')
template_dir = os.path.join(str(interface_dir), plexpy.CONFIG.INTERFACE)
TEMPLATE_LOOKUP = TemplateLookup(directories=[template_dir], default_filters=['unicode', 'h'],
error_handler=mako_error_handler)

http_root = plexpy.HTTP_ROOT
server_name = helpers.pms_name()
Expand All @@ -133,7 +137,7 @@ def serve_template(templatename, **kwargs):
_session = get_session_info()

try:
template = _hplookup.get_template(templatename)
template = TEMPLATE_LOOKUP.get_template(template_name)
return template.render(http_root=http_root, server_name=server_name, cache_param=cache_param,
_session=_session, **kwargs)
except Exception as e:
Expand Down

0 comments on commit d9b3b31

Please sign in to comment.