From dd35faf4226c0af489722d314068dff9df8f7b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristi=20V=C3=AEjdea?= Date: Mon, 4 Mar 2019 03:35:21 +0200 Subject: [PATCH] Improve performance of schema views This removes swagger validation step and adds a cache layer to the swagger schema view. On my machine, the end result is sub-second response times instead of ~10 second response times for `/api/swagger.json`. --- netbox/netbox/urls.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/netbox/netbox/urls.py b/netbox/netbox/urls.py index 45c99beb9..ab3fcf5c6 100644 --- a/netbox/netbox/urls.py +++ b/netbox/netbox/urls.py @@ -18,6 +18,7 @@ schema_view = get_schema_view( license=openapi.License(name="Apache v2 License"), ), validators=['flex', 'ssv'], + validators=[], public=True, ) @@ -50,9 +51,9 @@ _patterns = [ url(r'^api/secrets/', include('secrets.api.urls')), url(r'^api/tenancy/', include('tenancy.api.urls')), url(r'^api/virtualization/', include('virtualization.api.urls')), - url(r'^api/docs/$', schema_view.with_ui('swagger'), name='api_docs'), - url(r'^api/redoc/$', schema_view.with_ui('redoc'), name='api_redocs'), - url(r'^api/swagger(?P.json|.yaml)$', schema_view.without_ui(), name='schema_swagger'), + url(r'^api/docs/$', schema_view.with_ui('swagger', cache_timeout=600), name='api_docs'), + url(r'^api/redoc/$', schema_view.with_ui('redoc', cache_timeout=600), name='api_redocs'), + url(r'^api/swagger(?P.json|.yaml)$', schema_view.without_ui(cache_timeout=600), name='schema_swagger'), # Serving static media in Django to pipe it through LoginRequiredMiddleware url(r'^media/(?P.*)$', serve, {'document_root': settings.MEDIA_ROOT}),