feat(archive-cache): added logging and relative imports

This commit is contained in:
RhodeCode Admin 2024-06-06 16:54:19 +02:00
parent fd5f035c74
commit 4ce101104b
2 changed files with 15 additions and 5 deletions

View file

@ -26,8 +26,9 @@ import typing
import zlib
import sqlite3
from rhodecode.lib.ext_json import json
from ...ext_json import json
from .lock import GenerationLock
from .utils import format_size
log = logging.getLogger(__name__)
@ -314,6 +315,9 @@ class FanoutCache:
select_policy = EVICTION_POLICY[policy]['evict']
log.debug('Running eviction policy \'%s\', and checking for size limit: %s',
policy, format_size(size_limit))
if select_policy is None:
return 0
@ -349,20 +353,27 @@ class FanoutCache:
db.bulk_insert(data)
((total_size,),) = db.sql('SELECT COALESCE(SUM(size), 0) FROM archive_cache').fetchall()
log.debug('Analyzed %s keys, occupied: %s', len(data), format_size(total_size))
select_policy_qry = select_policy.format(fields='key_file_path, full_path, size')
sorted_keys = db.sql(select_policy_qry).fetchall()
removed_items = 0
removed_size = 0
for key, cached_file, size in sorted_keys:
# simulate removal impact BEFORE removal
total_size -= size
if total_size <= size_limit:
# we obtained what we wanted...
break
os.remove(cached_file)
os.remove(key)
return
removed_items += 1
removed_size += size
log.debug('Removed %s cache archives, and reduced size: %s', removed_items, format_size(removed_size))
return removed_items
def get_archival_config(config):

View file

@ -17,8 +17,7 @@
# and proprietary license terms, please see https://rhodecode.com/licenses/
import redis
from rhodecode.lib._vendor import redis_lock
from ..._vendor import redis_lock
from .utils import ArchiveCacheLock