mirror of https://github.com/zulip/zulip.git
api docs: Load the OpenAPI file only when needed.
We found out in #9953 that, appparently, loading the OpenAPI file was taking abut a 5% of the Zulip server startup time. Since in many cases (especially in development) having the file loaded won't be necessary at all, we read it on the first time data from the OpenAPI spec is needed. Tweaked by tabbott to add a test.
This commit is contained in:
parent
25d2efb9ca
commit
e1662024d1
|
@ -23,7 +23,7 @@ EXCLUDE_PROPERTIES = {
|
|||
class OpenAPISpec():
|
||||
def __init__(self, path: str) -> None:
|
||||
self.path = path
|
||||
self.reload()
|
||||
self.last_update = None # type: Optional[float]
|
||||
|
||||
def reload(self) -> None:
|
||||
self.last_update = os.path.getmtime(self.path)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import mock
|
||||
from typing import Dict, Any
|
||||
|
||||
import zerver.lib.openapi as openapi
|
||||
|
@ -132,3 +133,8 @@ class OpenAPIToolsTest(ZulipTestCase):
|
|||
# Check that the file has been reloaded by verifying that the last
|
||||
# update date isn't zero anymore
|
||||
self.assertNotEqual(openapi_spec.last_update, 0)
|
||||
|
||||
# Now verify calling it again doesn't call reload
|
||||
with mock.patch('zerver.lib.openapi.openapi_spec.reload') as mock_reload:
|
||||
get_openapi_fixture(TEST_ENDPOINT, TEST_METHOD)
|
||||
self.assertFalse(mock_reload.called)
|
||||
|
|
Loading…
Reference in New Issue