makrdev's Thread
I created triggers to cascade delete operations for relational tables. (when user is deleted it cascades to relation tables.) It fails when we have too many documents. How can I handle this situation?
7 Replies
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. If this is a support-related question, please create a post in #support-community. If not, carry on! Thanks!
Solution:
Check out the convex ents documentation and source code, which describes how you can split cascading deletes across multiple mutations https://labs.convex.dev/convex-ents/schema/deletes
Cascading Deletes - Convex Ents
Relations, default values, unique fields and more for Convex
@lee Hey Lee, what do you think about the solution I shared above?
That should work, yep! The only issue would be if you want the deletions to appear transactional, which you can do with the pattern in convex ents
But if you just want everything deleted eventually, your solution looks great
There was an error in one of the cascade triggers, and it prevented all of them deleting other resources. Is that what you mean by 'transactional'?
Oh you can probably fix that by doing the pagination entirely within batchDeleteFiles. The trigger should do
runAfter(0, ...batchDeleteFiles, { projectId: change.id, cursor: null, numItems: 1000 })