Partition mail retention by tenant
This commit is contained in:
@@ -874,15 +874,19 @@ def resend_delivery_command(
|
||||
def purge_expired(
|
||||
session: Session,
|
||||
*,
|
||||
tenant_id: str | None = None,
|
||||
limit: int = 250,
|
||||
) -> dict[str, object]:
|
||||
now = utcnow()
|
||||
clauses = [
|
||||
MailDeliveryCommand.expires_at <= now,
|
||||
MailDeliveryCommand.payload_purged_at.is_(None),
|
||||
]
|
||||
if tenant_id:
|
||||
clauses.append(MailDeliveryCommand.tenant_id == tenant_id)
|
||||
commands = session.scalars(
|
||||
select(MailDeliveryCommand)
|
||||
.where(
|
||||
MailDeliveryCommand.expires_at <= now,
|
||||
MailDeliveryCommand.payload_purged_at.is_(None),
|
||||
)
|
||||
.where(*clauses)
|
||||
.order_by(MailDeliveryCommand.expires_at)
|
||||
.limit(max(1, min(int(limit), 1000)))
|
||||
).all()
|
||||
|
||||
Reference in New Issue
Block a user