OpenAPI: Import yamole inside a function for performance.

This saves about 1% of the runtime of `manage.py showmigrations`
This commit is contained in:
Tim Abbott 2018-08-08 13:33:49 -07:00
parent 4d03c15848
commit de45853c99
1 changed files with 5 additions and 2 deletions

View File

@ -3,8 +3,6 @@
import os
from typing import Any, Dict, List, Optional
from yamole import YamoleParser
OPENAPI_SPEC_PATH = os.path.abspath(os.path.join(
os.path.dirname(__file__),
'../openapi/zulip.yaml'))
@ -26,6 +24,11 @@ class OpenAPISpec():
self.last_update = None # type: Optional[float]
def reload(self) -> None:
# Because importing yamole (and in turn, yaml) takes
# significant time, and we only use python-yaml for our API
# docs, importing it lazily here is a significant optimization
# to `manage.py` startup.
from yamole import YamoleParser
self.last_update = os.path.getmtime(self.path)
with open(self.path) as f:
yaml_parser = YamoleParser(f)