Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding option to disable the _get_disk_usage #638

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions server/config.yaml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,9 @@ privileges:
## usage: schema://user:password@host:port/database_name
## example: postgres://szuru:dog@localhost:5432/szuru_test
#database:


## get the data dir usage
## false disabled
## true enabled ( default )
data_dir_get_usage: true
31 changes: 16 additions & 15 deletions server/szurubooru/api/info_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,23 @@


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"]:
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


Expand Down