Beispiel #1
0
    def repo_stats(self, repo_name, commit_id):
        _namespace = caches.get_repo_namespace_key(caches.SUMMARY_STATS,
                                                   repo_name)
        show_stats = bool(c.rhodecode_db_repo.enable_statistics)
        cache_manager = caches.get_cache_manager('repo_cache_long', _namespace)
        _cache_key = caches.compute_key_from_params(repo_name, commit_id,
                                                    show_stats)

        def compute_stats():
            code_stats = {}
            size = 0
            try:
                scm_instance = c.rhodecode_db_repo.scm_instance()
                commit = scm_instance.get_commit(commit_id)

                for node in commit.get_filenodes_generator():
                    size += node.size
                    if not show_stats:
                        continue
                    ext = lower(node.extension)
                    ext_info = LANGUAGES_EXTENSIONS_MAP.get(ext)
                    if ext_info:
                        if ext in code_stats:
                            code_stats[ext]['count'] += 1
                        else:
                            code_stats[ext] = {"count": 1, "desc": ext_info}
            except EmptyRepositoryError:
                pass
            return {
                'size': h.format_byte_size_binary(size),
                'code_stats': code_stats
            }

        stats = cache_manager.get(_cache_key, createfunc=compute_stats)
        return stats
Beispiel #2
0
    def get_all_settings(self, cache=False):
        def _compute():
            q = self._get_settings_query()
            if not q:
                raise Exception('Could not get application settings !')

            settings = {
                'rhodecode_' + result.app_settings_name: result.app_settings_value
                for result in q
            }
            return settings

        if cache:
            log.debug('Fetching app settings using cache')
            repo = self._get_repo(self.repo) if self.repo else None
            namespace = 'rhodecode_settings'
            cache_manager = caches.get_cache_manager(
                'sql_cache_short', namespace)
            _cache_key = (
                "get_repo_{}_settings".format(repo.repo_id)
                if repo else "get_app_settings")

            return cache_manager.get(_cache_key, createfunc=_compute)

        else:
            return _compute()
    def test_cache_manager_init_undefined_namespace(self):
        cache_manager_instance = caches.get_cache_manager(
            'repo_cache_long_undefined', 'my_cache')
        assert cache_manager_instance

        def_config = caches.DEFAULT_CACHE_MANAGER_CONFIG.copy()
        def_config.pop('type')
        assert cache_manager_instance.nsargs == def_config

        assert isinstance(
            cache_manager_instance.namespace, MemoryLRUNamespaceManagerBase)
    def test_store_and_get_value_from_manager(self):
            cache_manger_instance = caches.get_cache_manager(
                'repo_cache_long', 'my_cache_store')

            _cache_key = caches.compute_key_from_params('foo_bar', 'multicall')

            def compute():
                return time.time()

            result = set()
            for x in xrange(10):
                ret = cache_manger_instance.get(_cache_key, createfunc=compute)
                result.add(ret)

            # once computed we have only one value after executing it 10x
            assert len(result) == 1
    def test_store_and_invalidate_value_from_manager(self):
        cache_manger_instance = caches.get_cache_manager(
            'repo_cache_long', 'my_cache_store')

        def compute():
            return time.time()

        added_keys = []
        for i in xrange(3):
            _cache_key = caches.compute_key_from_params('foo_bar', 'p%s' % i)
            added_keys.append(_cache_key)
            for x in xrange(10):
                cache_manger_instance.get(_cache_key, createfunc=compute)

        for key in added_keys:
            assert cache_manger_instance[key]

        caches.clear_cache_manager(cache_manger_instance)

        for key in added_keys:
            assert key not in cache_manger_instance
        assert len(cache_manger_instance.namespace.keys()) == 0
Beispiel #6
0
def get_auth_cache_manager(custom_ttl=None):
    return caches.get_cache_manager('auth_plugins', 'rhodecode.authentication',
                                    custom_ttl)
 def test_cache_manager_init(self, repo_name):
     cache_manager_instance = caches.get_cache_manager(
         repo_name, 'my_cache')
     assert cache_manager_instance
Beispiel #8
0
 def invalidate_settings_cache(self):
     namespace = 'rhodecode_settings'
     cache_manager = caches.get_cache_manager('sql_cache_short', namespace)
     caches.clear_cache_manager(cache_manager)
 def __get_tree_cache_manager(self, repo_name, namespace_type):
     _namespace = caches.get_repo_namespace_key(namespace_type, repo_name)
     return caches.get_cache_manager('repo_cache_long', _namespace)