Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🔧 Register the orphaned-guest cleanup cron (#3055)

Luke Vella1b085700afec
diff --git a/apps/web/src/features/user/mutations.ts b/apps/web/src/features/user/mutations.ts
index fc803b42c..ca61a78be 100644
--- a/apps/web/src/features/user/mutations.ts
+++ b/apps/web/src/features/user/mutations.ts
@@ -147,7 +147,12 @@ export async function hardDeleteUser({ userId }: { userId: string }) {
await prisma.user.delete({ where: { id: userId } });
}
-const DELETE_ORPHANED_ANONYMOUS_USERS_BATCH_SIZE = 100;
+// Each batch is one round trip, and the handler's budget is maxDuration (300s),
+// so this sets how much backlog a single run can clear. 100 left the job unable
+// to drain even a modest arrivals backlog inside the budget; 1000 keeps the
+// per-batch transaction small while giving a run an order of magnitude more
+// headroom. Raising it further trades that headroom against lock and WAL size.
+const DELETE_ORPHANED_ANONYMOUS_USERS_BATCH_SIZE = 1000;
/**
* Delete orphaned anonymous guest users: guests that own no resources and
@@ -155,9 +160,14 @@ const DELETE_ORPHANED_ANONYMOUS_USERS_BATCH_SIZE = 100;
*
* Two guards, both required:
* - The `lastSeenAt` window IS the liveness check. Prod sessions live in
- * Redis, so we can't probe them at delete time; but session TTL equals
- * this window and every session refresh bumps `lastSeenAt`, so a guest
- * below the cutoff provably has no live session left to orphan.
+ * Redis, so we can't probe them at delete time. What rules out a live
+ * session is the session TTL: it equals this window, so any session
+ * belonging to a guest below the cutoff has already expired. `lastSeenAt`
+ * is a lower bound on that expiry, not a record of it — a returning guest
+ * gets a fresh session, and `session.create` writes `lastSeenAt`, lifting
+ * them back above the cutoff. Note the value can also predate any session
+ * at all: rows carrying the column's backfill default were never observed,
+ * so read a stale `lastSeenAt` as "no session since", not "last active at".
* - The resource filter guards the cascade. A guest's polls/comments are
* onDelete: Cascade, so deleting one who still owns a live poll would
* destroy everyone's votes/comments.
diff --git a/apps/web/vercel.json b/apps/web/vercel.json
index 3003917fb..5cf1099e7 100644
--- a/apps/web/vercel.json
+++ b/apps/web/vercel.json
@@ -22,6 +22,10 @@
{
"path": "/api/house-keeping/remove-deleted-users",
"schedule": "0 7 * * *"
+ },
+ {
+ "path": "/api/house-keeping/delete-orphaned-anonymous-users",
+ "schedule": "30 7 * * *"
}
]
}