Last active
May 3, 2025 17:00
-
-
Save jamwt/a04a0de0a07664ad2511123b119ed7b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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