Skip to content

Commit 7cde40b

Browse files
committed
chore: should also delete messages when deleting a thread
1 parent b7dd314 commit 7cde40b

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

  • apps/backend-convex/functions/threads

apps/backend-convex/functions/threads/mutate.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ export const del = mutation({
3636

3737
await assertThreadAccess(ctx, { thread, lockerKey: args.lockerKey })
3838

39+
const messages = await ctx.db.query('messages')
40+
// Use this index because its likely to be cached
41+
.withIndex('by_thread_and_timestamp', q => q.eq('threadId', args.threadId))
42+
.collect()
43+
3944
await ctx.db.delete(args.threadId)
45+
await Promise.all(messages.map(message => ctx.db.delete(message._id)))
4046
},
4147
})
4248

0 commit comments

Comments
 (0)