Skip to content

Instantly share code, notes, and snippets.

@jamwt
Last active May 3, 2025 17:00
Show Gist options
  • Select an option

  • Save jamwt/a04a0de0a07664ad2511123b119ed7b8 to your computer and use it in GitHub Desktop.

Select an option

Save jamwt/a04a0de0a07664ad2511123b119ed7b8 to your computer and use it in GitHub Desktop.
const deletionWorkpool = workpool(retry by default, retry 10+ times, concurrency = 10)
// Called by the user, public & fast. You can retain the workpool
// job id if you want to be able to indicate
// if the deletion is done yet.
deleteAll -> mutation {
deletionWorkpool.enqueueAction(internal.deleteAllUserMessages, {user})
}
// Drive many small transactions clearing batches while some exist.
deleteAllUserMessages -> internalAction {
do {
const more = ctx.runMutation(internal.deleteUserMessageBatch, ctx.user);
} while (more)
}
// Simple mutation.
deleteUserMessageBatch -> internalMutation {
const batch = ctx.db.query("messages").withIndex("by_user", ...).take(51)
// map over and delete 50
return batch.length > 50
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment