Skip to content

Commit

Permalink
Cache messages that we have already loaded.
Browse files Browse the repository at this point in the history
Messages were being loaded each time the `MESSAGES` attribute of `site`
was accessed. This commit switches to using cached values.
  • Loading branch information
punchagan committed May 19, 2016
1 parent 67f6a0c commit a6ac0f8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions nikola/nikola.py
Expand Up @@ -337,6 +337,7 @@ def __init__(self, **config):
self._scanned = False
self._template_system = None
self._THEMES = None
self._MESSAGES = None
self.debug = DEBUG
self.loghandlers = utils.STDERR_HANDLER # TODO remove on v8
self.colorful = config.pop('__colorful__', False)
Expand Down Expand Up @@ -1069,9 +1070,11 @@ def _get_themes(self):

def _get_messages(self):
try:
return utils.load_messages(self.THEMES,
self.translations,
self.default_lang)
if self._MESSAGES is None:
self._MESSAGES = utils.load_messages(self.THEMES,
self.translations,
self.default_lang)
return self._MESSAGES
except utils.LanguageNotFoundError as e:
utils.LOGGER.error('''Cannot load language "{0}". Please make sure it is supported by Nikola itself, or that you have the appropriate messages files in your themes.'''.format(e.lang))
sys.exit(1)
Expand Down

0 comments on commit a6ac0f8

Please sign in to comment.