LMS startup optimization: Load pynliner locally.

pynliner imports cssutils, which has an expensive initialization. All
told, it can account for 15-20% of "fast" LMS startup (without asset
compilation). So we're going to load it locally here so that we delay
that one-time hit until we actually do the (rare) operation that is
sending a credit notification email.
This commit is contained in:
David Ormsbee
2017-02-24 19:09:35 -05:00
parent c8f7587f6b
commit b3a62bd252

View File

@@ -5,7 +5,6 @@ This file contains utility functions which will responsible for sending emails.
import os
import logging
import pynliner
import urlparse
import uuid
import HTMLParser
@@ -145,6 +144,13 @@ def with_inline_css(html_without_css):
with open(css_filepath, "r") as _file:
css_content = _file.read()
# pynliner imports cssutils, which has an expensive initialization. All
# told, it can account for 15-20% of "fast" LMS startup (without asset
# compilation). So we're going to load it locally here so that we delay
# that one-time hit until we actually do the (rare) operation that is
# sending a credit notification email.
import pynliner
# insert style tag in the html and run pyliner.
html_with_inline_css = pynliner.fromString('<style>' + css_content + '</style>' + html_without_css)
return html_with_inline_css