Don't cache database size

This commit is contained in:
Joakim Hellsén 2024-03-15 14:50:06 +01:00
commit 88c958ef12
No known key found for this signature in database
GPG key ID: D196AE66FEBE1DC9

View file

@ -2,7 +2,6 @@ from __future__ import annotations
import logging import logging
from django.core.cache import cache
from django.db import connection from django.db import connection
logger: logging.Logger = logging.getLogger(__name__) logger: logging.Logger = logging.getLogger(__name__)
@ -14,13 +13,6 @@ def get_db_size() -> str:
Returns: Returns:
str: The size of the database. str: The size of the database.
""" """
# Try to get value from cache
db_size = cache.get("db_size")
if db_size is not None:
logger.debug("Got db_size from cache")
return db_size
# Get SQLite database size # Get SQLite database size
with connection.cursor() as cursor: with connection.cursor() as cursor:
cursor.execute("PRAGMA page_size") cursor.execute("PRAGMA page_size")
@ -32,7 +24,4 @@ def get_db_size() -> str:
page_count = page_count_result[0] if page_count_result else None page_count = page_count_result[0] if page_count_result else None
db_size = page_size * page_count if page_size and page_count else None db_size = page_size * page_count if page_size and page_count else None
cache.set("db_size", db_size, 60 * 15)
return f"{db_size / 1024 / 1024:.2f} MB" if db_size is not None else "0 MB" return f"{db_size / 1024 / 1024:.2f} MB" if db_size is not None else "0 MB"