# HG changeset patch # User RhodeCode Admin # Date 2023-04-04 18:12:51 # Node ID 58fdadac3874aa4967c729cc14b803e2235f6bb9 # Parent 61a143737f9f1d5ef14846e772c364b5e418b413 caches: fixed dbm keys calls to use bytes diff --git a/vcsserver/lib/rc_cache/backends.py b/vcsserver/lib/rc_cache/backends.py --- a/vcsserver/lib/rc_cache/backends.py +++ b/vcsserver/lib/rc_cache/backends.py @@ -37,7 +37,7 @@ from dogpile.cache.api import Serializer from pyramid.settings import asbool from vcsserver.lib.memory_lru_dict import LRUDict, LRUDictDebug -from vcsserver.str_utils import safe_str +from vcsserver.str_utils import safe_str, safe_bytes _default_max_size = 1024 @@ -111,20 +111,20 @@ class FileNamespaceBackend(PickleSeriali def __repr__(self): return '{} `{}`'.format(self.__class__, self.filename) - def list_keys(self, prefix=''): - prefix = '{}:{}'.format(self.key_prefix, prefix) + def list_keys(self, prefix: bytes = b''): + prefix = b'%b:%b' % (safe_bytes(self.key_prefix), safe_bytes(prefix)) - def cond(v): + def cond(dbm_key: bytes): if not prefix: return True - if v.startswith(prefix): + if dbm_key.startswith(prefix): return True return False with self._dbm_file(True) as dbm: try: - return list(filter(cond, list(dbm.keys()))) + return list(filter(cond, dbm.keys())) except Exception: log.error('Failed to fetch DBM keys from DB: %s', self.get_store()) raise