21 lines
511 B
Python
21 lines
511 B
Python
from datetime import datetime
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from models import ChatAttachment
|
|
|
|
|
|
def purge_expired_chat_attachments(
|
|
db: Session,
|
|
*,
|
|
now: datetime | None = None,
|
|
) -> int:
|
|
"""Remove expired derived image data; raw image bytes are never persisted."""
|
|
count = db.query(ChatAttachment).filter(
|
|
ChatAttachment.expires_at < (now or datetime.utcnow())
|
|
).delete(synchronize_session=False)
|
|
if count:
|
|
db.commit()
|
|
db.expire_all()
|
|
return count
|