forked from claw/flaskpaste
cleanup: add expired short url cleanup
This commit is contained in:
@@ -14,12 +14,14 @@ _cleanup_times: dict[str, float] = {
|
|||||||
"hashes": 0.0,
|
"hashes": 0.0,
|
||||||
"rate_limits": 0.0,
|
"rate_limits": 0.0,
|
||||||
"audit": 0.0,
|
"audit": 0.0,
|
||||||
|
"short_urls": 0.0,
|
||||||
}
|
}
|
||||||
_CLEANUP_INTERVALS = {
|
_CLEANUP_INTERVALS = {
|
||||||
"pastes": 3600, # 1 hour
|
"pastes": 3600, # 1 hour
|
||||||
"hashes": 900, # 15 minutes
|
"hashes": 900, # 15 minutes
|
||||||
"rate_limits": 300, # 5 minutes
|
"rate_limits": 300, # 5 minutes
|
||||||
"audit": 86400, # 24 hours
|
"audit": 86400, # 24 hours
|
||||||
|
"short_urls": 3600, # 1 hour
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -73,5 +75,14 @@ def run_scheduled_cleanup():
|
|||||||
if count > 0:
|
if count > 0:
|
||||||
current_app.logger.info(f"Cleaned up {count} old audit log entries")
|
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
|
from app.api import routes # noqa: E402, F401
|
||||||
|
|||||||
@@ -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 content_hashes")
|
||||||
db_module._memory_db_holder.execute("DELETE FROM issued_certificates")
|
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 certificate_authority")
|
||||||
|
db_module._memory_db_holder.execute("DELETE FROM short_urls")
|
||||||
db_module._memory_db_holder.commit()
|
db_module._memory_db_holder.commit()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user