From 187869c21d0b44c1e54b10b93e3cbacdc57fb624 Mon Sep 17 00:00:00 2001 From: Theenoro Date: Mon, 4 Mar 2024 01:01:17 +0100 Subject: [PATCH] Update info_api.py added a way to disable getDiskUsageInfo --- server/szurubooru/api/info_api.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/server/szurubooru/api/info_api.py b/server/szurubooru/api/info_api.py index 757b09cf..667ffaa4 100644 --- a/server/szurubooru/api/info_api.py +++ b/server/szurubooru/api/info_api.py @@ -10,22 +10,23 @@ _cache_result = None # type: Optional[int] def _get_disk_usage() -> int: - global _cache_time, _cache_result - threshold = timedelta(hours=48) - now = datetime.utcnow() - if _cache_time and _cache_time > now - threshold: - assert _cache_result is not None - return _cache_result total_size = 0 - for dir_path, _, file_names in os.walk(config.config["data_dir"]): - for file_name in file_names: - file_path = os.path.join(dir_path, file_name) - try: - total_size += os.path.getsize(file_path) - except FileNotFoundError: - pass - _cache_time = now - _cache_result = total_size + if config.config["data_dir_get_usage"] == 1: + global _cache_time, _cache_result + threshold = timedelta(hours=48) + now = datetime.utcnow() + if _cache_time and _cache_time > now - threshold: + assert _cache_result is not None + return _cache_result + for dir_path, _, file_names in os.walk(config.config["data_dir"]): + for file_name in file_names: + file_path = os.path.join(dir_path, file_name) + try: + total_size += os.path.getsize(file_path) + except FileNotFoundError: + pass + _cache_time = now + _cache_result = total_size return total_size