diff --git a/app/api/__init__.py b/app/api/__init__.py index 088a30e..26ccb1f 100644 --- a/app/api/__init__.py +++ b/app/api/__init__.py @@ -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 diff --git a/tests/conftest.py b/tests/conftest.py index 187ac31..bead609 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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()