[GH-ISSUE #5654] [Enhancement] Add cascade delete for collections to improve deletion performance and simplify code #2191

Closed
opened 2026-03-16 23:32:12 +03:00 by kerem · 1 comment
Owner

Originally created by @shaezard on GitHub (Dec 3, 2025).
Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/5654

Originally assigned to: @shaezard on GitHub.

Description

When deleting a UserCollection or TeamCollection that contains nested child collections and requests, the current implementation uses recursive application-level deletion. This approach:

  1. Increases database round-trips - Each child collection and request requires separate DELETE queries
  2. Risk of orphaned records - If the process fails mid-way, child records may be left orphaned
  3. Code complexity - Requires manual recursive logic (deleteCollectionData) to handle nested deletions

Current Behavior

The deleteUserCollection and deleteTeamCollection methods recursively:

  1. Fetch all child collections
  2. Recursively call delete on each child
  3. Delete all requests in the collection
  4. Finally delete the collection itself

This results in N+1 query patterns for deeply nested collections.

Proposed Solution

Add onDelete: Cascade to the Prisma schema for:

  • TeamCollection.parentTeamCollection relationship
  • UserRequest.userCollectionUserCollection relationship

This delegates cascading deletions to the database level, which:

  • Executes as a single atomic transaction
  • Eliminates orphaned records risk
  • Significantly improves performance for nested collections
  • Simplifies service layer code by removing recursive deletion logic

Affected Components

  • packages/hoppscotch-backend/prisma/schema.prisma
  • packages/hoppscotch-backend/src/user-collection/user-collection.service.ts
  • packages/hoppscotch-backend/src/team-collection/team-collection.service.ts

Additional Context

The TeamCollectionTeam and UserRequestUser relationships already use onDelete: Cascade, so this change follows the existing pattern in the codebase.

Originally created by @shaezard on GitHub (Dec 3, 2025). Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/5654 Originally assigned to: @shaezard on GitHub. ## Description When deleting a `UserCollection` or `TeamCollection` that contains nested child collections and requests, the current implementation uses recursive application-level deletion. This approach: 1. **Increases database round-trips** - Each child collection and request requires separate DELETE queries 2. **Risk of orphaned records** - If the process fails mid-way, child records may be left orphaned 3. **Code complexity** - Requires manual recursive logic (`deleteCollectionData`) to handle nested deletions ## Current Behavior The `deleteUserCollection` and `deleteTeamCollection` methods recursively: 1. Fetch all child collections 2. Recursively call delete on each child 3. Delete all requests in the collection 4. Finally delete the collection itself This results in N+1 query patterns for deeply nested collections. ## Proposed Solution Add `onDelete: Cascade` to the Prisma schema for: - `TeamCollection.parent` → `TeamCollection` relationship - `UserRequest.userCollection` → `UserCollection` relationship This delegates cascading deletions to the database level, which: - ✅ Executes as a single atomic transaction - ✅ Eliminates orphaned records risk - ✅ Significantly improves performance for nested collections - ✅ Simplifies service layer code by removing recursive deletion logic ## Affected Components - `packages/hoppscotch-backend/prisma/schema.prisma` - `packages/hoppscotch-backend/src/user-collection/user-collection.service.ts` - `packages/hoppscotch-backend/src/team-collection/team-collection.service.ts` ## Additional Context The `TeamCollection` → `Team` and `UserRequest` → `User` relationships already use `onDelete: Cascade`, so this change follows the existing pattern in the codebase.
kerem closed this issue 2026-03-16 23:32:17 +03:00
Author
Owner

@jamesgeorge007 commented on GitHub (Jan 28, 2026):

This is now addressed in the v2026.1.0 release.

<!-- gh-comment-id:3810949150 --> @jamesgeorge007 commented on GitHub (Jan 28, 2026): This is now addressed in the [v2026.1.0](https://github.com/hoppscotch/hoppscotch/releases/tag/2026.1.0) release.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#2191
No description provided.