From d488559e42adcc87979af4f92a7a63c4dafcceed Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Tue, 23 Nov 2021 18:02:44 +0100 Subject: [PATCH] added setting to disable tree fix --- cookbook/apps.py | 41 +++++++++++++++++++++-------------------- recipes/settings.py | 1 + 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/cookbook/apps.py b/cookbook/apps.py index 2e31731d..3297d692 100644 --- a/cookbook/apps.py +++ b/cookbook/apps.py @@ -17,23 +17,24 @@ class CookbookConfig(AppConfig): 'django.db.backends.postgresql']: import cookbook.signals # noqa - # when starting up run fix_tree to: - # a) make sure that nodes are sorted when switching between sort modes - # b) fix problems, if any, with tree consistency - with scopes_disabled(): - try: - from cookbook.models import Keyword, Food - Keyword.fix_tree(fix_paths=True) - Food.fix_tree(fix_paths=True) - except OperationalError: - if DEBUG: - traceback.print_exc() - pass # if model does not exist there is no need to fix it - except ProgrammingError: - if DEBUG: - traceback.print_exc() - pass # if migration has not been run database cannot be fixed yet - except Exception: - if DEBUG: - traceback.print_exc() - pass # dont break startup just because fix could not run, need to investigate cases when this happens + if not settings.DISABLE_TREE_FIX_STARTUP: + # when starting up run fix_tree to: + # a) make sure that nodes are sorted when switching between sort modes + # b) fix problems, if any, with tree consistency + with scopes_disabled(): + try: + from cookbook.models import Keyword, Food + Keyword.fix_tree(fix_paths=True) + Food.fix_tree(fix_paths=True) + except OperationalError: + if DEBUG: + traceback.print_exc() + pass # if model does not exist there is no need to fix it + except ProgrammingError: + if DEBUG: + traceback.print_exc() + pass # if migration has not been run database cannot be fixed yet + except Exception: + if DEBUG: + traceback.print_exc() + pass # dont break startup just because fix could not run, need to investigate cases when this happens diff --git a/recipes/settings.py b/recipes/settings.py index 73dff9cd..6edb406b 100644 --- a/recipes/settings.py +++ b/recipes/settings.py @@ -151,6 +151,7 @@ MIDDLEWARE = [ ] SORT_TREE_BY_NAME = bool(int(os.getenv('SORT_TREE_BY_NAME', False))) +DISABLE_TREE_FIX_STARTUP = bool(int(os.getenv('DISABLE_TREE_FIX_STARTUP', False))) if bool(int(os.getenv('SQL_DEBUG', False))): MIDDLEWARE += ('recipes.middleware.SqlPrintingMiddleware',)