cleanup: add expired short url cleanup

This commit is contained in:
Username
2026-02-16 20:26:58 +01:00
parent 727fc84784
commit 0f63bb05e1
2 changed files with 12 additions and 0 deletions

View File

@@ -14,12 +14,14 @@ _cleanup_times: dict[str, float] = {
"hashes": 0.0,
"rate_limits": 0.0,
"audit": 0.0,
"short_urls": 0.0,
}
_CLEANUP_INTERVALS = {
"pastes": 3600, # 1 hour
"hashes": 900, # 15 minutes
"rate_limits": 300, # 5 minutes
"audit": 86400, # 24 hours
"short_urls": 3600, # 1 hour
}
@@ -73,5 +75,14 @@ def run_scheduled_cleanup():
if count > 0:
current_app.logger.info(f"Cleaned up {count} old audit log entries")
# Cleanup expired short URLs
if now - _cleanup_times["short_urls"] >= _CLEANUP_INTERVALS["short_urls"]:
_cleanup_times["short_urls"] = now
from app.database import cleanup_expired_short_urls
count = cleanup_expired_short_urls()
if count > 0:
current_app.logger.info(f"Cleaned up {count} expired short URL(s)")
from app.api import routes # noqa: E402, F401

View File

@@ -14,6 +14,7 @@ def _clear_database():
db_module._memory_db_holder.execute("DELETE FROM content_hashes")
db_module._memory_db_holder.execute("DELETE FROM issued_certificates")
db_module._memory_db_holder.execute("DELETE FROM certificate_authority")
db_module._memory_db_holder.execute("DELETE FROM short_urls")
db_module._memory_db_holder.commit()