changeset 8127:7fdefd3c5bd5

cache: drop setup_cache_regions - tg will already have done that and coerced the types correctly The configuration and type fixing will be invoked from make_base_app, and we will thus not have to do it: File "kallithea/config/middleware.py", line 31, in make_app_without_logging return make_base_app(global_conf, full_stack=full_stack, **app_conf) File ".../python3.7/site-packages/tg/configuration/app_config.py", line 176, in make_base_app wrap_app) File ".../python3.7/site-packages/tg/configurator/application.py", line 112, in _make_app app = TGApp(conf) File ".../python3.7/site-packages/tg/wsgiapp.py", line 49, in __init__ app_wrapper = wrapper(self.wrapped_dispatch, self.config) File ".../python3.7/site-packages/tg/appwrappers/caching.py", line 36, in __init__ self.options = parse_cache_config_options(config) File ".../python3.7/site-packages/beaker/util.py", line 430, in parse_cache_config_options This will fix a py3 problem where setup_cache_regions was run *after* beaker had coerced types, thus introducing string types in the config where beaker expected the integers it had put there.
author Mads Kiilerich <mads@kiilerich.com>
date Fri, 03 Jan 2020 01:55:06 +0100
parents 9584eb51ae52
children f537a6e23e2c
files kallithea/bin/kallithea_cli_base.py kallithea/lib/hooks.py kallithea/lib/utils.py kallithea/tests/scripts/manual_test_concurrency.py
diffstat 4 files changed, 2 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/bin/kallithea_cli_base.py	Fri Jan 03 02:16:42 2020 +0100
+++ b/kallithea/bin/kallithea_cli_base.py	Fri Jan 03 01:55:06 2020 +0100
@@ -75,7 +75,6 @@
                 logging.config.fileConfig(io.StringIO(config_string))
                 if config_file_initialize_app:
                     kallithea.config.middleware.make_app_without_logging(kallithea.CONFIG.global_conf, **kallithea.CONFIG.local_conf)
-                    kallithea.lib.utils.setup_cache_regions(kallithea.CONFIG)
                 return annotated(*args, **kwargs)
             return cli_command(runtime_wrapper)
         return annotator
--- a/kallithea/lib/hooks.py	Fri Jan 03 02:16:42 2020 +0100
+++ b/kallithea/lib/hooks.py	Fri Jan 03 01:55:06 2020 +0100
@@ -303,7 +303,6 @@
     """
     import paste.deploy
     import kallithea.config.middleware
-    import kallithea.lib.utils
 
     extras = get_hook_environment()
 
@@ -311,7 +310,6 @@
     kallithea.CONFIG = paste.deploy.appconfig('config:' + path_to_ini_file)
     #logging.config.fileConfig(ini_file_path) # Note: we are in a different process - don't use configured logging
     kallithea.config.middleware.make_app_without_logging(kallithea.CONFIG.global_conf, **kallithea.CONFIG.local_conf)
-    kallithea.lib.utils.setup_cache_regions(kallithea.CONFIG)
 
     repo_path = safe_unicode(repo_path)
     # fix if it's not a bare repo
--- a/kallithea/lib/utils.py	Fri Jan 03 02:16:42 2020 +0100
+++ b/kallithea/lib/utils.py	Fri Jan 03 01:55:06 2020 +0100
@@ -33,10 +33,9 @@
 import traceback
 from distutils.version import StrictVersion
 
-import beaker
+import beaker.cache
 import mercurial.config
 import mercurial.ui
-from beaker.cache import _cache_decorate
 from tg.i18n import ugettext as _
 
 import kallithea.config.conf
@@ -622,36 +621,6 @@
 # CACHE RELATED METHODS
 #===============================================================================
 
-# set cache regions for beaker so celery can utilise it
-def setup_cache_regions(settings):
-    # Create dict with just beaker cache configs with prefix stripped
-    cache_settings = {'regions': None}
-    prefix = 'beaker.cache.'
-    for key in settings:
-        if key.startswith(prefix):
-            name = key[len(prefix):]
-            cache_settings[name] = settings[key]
-    # Find all regions, apply defaults, and apply to beaker
-    if cache_settings['regions']:
-        for region in cache_settings['regions'].split(','):
-            region = region.strip()
-            prefix = region + '.'
-            region_settings = {}
-            for key in cache_settings:
-                if key.startswith(prefix):
-                    name = key[len(prefix):]
-                    region_settings[name] = cache_settings[key]
-            region_settings.setdefault('expire',
-                                       cache_settings.get('expire', '60'))
-            region_settings.setdefault('lock_dir',
-                                       cache_settings.get('lock_dir'))
-            region_settings.setdefault('data_dir',
-                                       cache_settings.get('data_dir'))
-            region_settings.setdefault('type',
-                                       cache_settings.get('type', 'memory'))
-            beaker.cache.cache_regions[region] = region_settings
-
-
 def conditional_cache(region, prefix, condition, func):
     """
 
@@ -674,6 +643,6 @@
     if condition:
         log.debug('conditional_cache: True, wrapping call of '
                   'func: %s into %s region cache' % (region, func))
-        wrapped = _cache_decorate((prefix,), None, None, region)(func)
+        wrapped = beaker.cache._cache_decorate((prefix,), None, None, region)(func)
 
     return wrapped
--- a/kallithea/tests/scripts/manual_test_concurrency.py	Fri Jan 03 02:16:42 2020 +0100
+++ b/kallithea/tests/scripts/manual_test_concurrency.py	Fri Jan 03 01:55:06 2020 +0100
@@ -41,7 +41,6 @@
 
 from kallithea.config.environment import load_environment
 from kallithea.lib.auth import get_crypt_password
-from kallithea.lib.utils import setup_cache_regions
 from kallithea.model import meta
 from kallithea.model.base import init_model
 from kallithea.model.db import Repository, Ui, User
@@ -52,8 +51,6 @@
 conf = appconfig('config:development.ini', relative_to=rel_path)
 load_environment(conf.global_conf, conf.local_conf)
 
-setup_cache_regions(conf)
-
 USER = TEST_USER_ADMIN_LOGIN
 PASS = TEST_USER_ADMIN_PASS
 HOST = 'server.local'