diff --git a/manage.py b/manage.py index bc7b310077..83164e8190 100755 --- a/manage.py +++ b/manage.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import os import sys +import types BASE_DIR = os.path.dirname(os.path.abspath(__file__)) sys.path.append(BASE_DIR) @@ -21,6 +22,15 @@ if __name__ == "__main__": print("Error accessing Zulip secrets; manage.py in production must be run as the zulip user.") sys.exit(1) + # Performance Hack: We make the pika.adapters.twisted_connection + # module unavailable, to save ~100ms of import time for most Zulip + # management commands for code we don't use. The correct + # long-term fix for this will be to get a setting integrated + # upstream to disable pika importing this. + # See https://github.com/pika/pika/issues/1128 + sys.modules['pika.adapters.twisted_connection'] = types.ModuleType( + 'pika.adapters.twisted_connection') + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "zproject.settings") from django.conf import settings from django.core.management import execute_from_command_line diff --git a/zproject/wsgi.py b/zproject/wsgi.py index 9fbbafc561..b00e13ee3a 100644 --- a/zproject/wsgi.py +++ b/zproject/wsgi.py @@ -15,11 +15,21 @@ framework. """ import os import sys +import types BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(BASE_DIR) import scripts.lib.setup_path_on_import +# Performance Hack: We make the pika.adapters.twisted_connection +# module unavailable, to save ~100ms of import time for most Zulip +# management commands for code we don't use. The correct +# long-term fix for this will be to get a setting integrated +# upstream to disable pika importing this. +# See https://github.com/pika/pika/issues/1128 +sys.modules['pika.adapters.twisted_connection'] = types.ModuleType( + 'pika.adapters.twisted_connection') + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "zproject.settings") import django django.setup() # We need to call setup to load applications.