Skip to content

fix: Deleting an asset is very slow#697

Open
shreyanshsingh1234-dev wants to merge 1 commit intoaiondemand:developfrom
shreyanshsingh1234-dev:fix-error
Open

fix: Deleting an asset is very slow#697
shreyanshsingh1234-dev wants to merge 1 commit intoaiondemand:developfrom
shreyanshsingh1234-dev:fix-error

Conversation

@shreyanshsingh1234-dev
Copy link

Summary
Optimized the performance of resource deletion (e.g., datasets) by refactoring many-to-many orphan deletion triggers and adding missing database indexes.

The Problem
Previously, deleting a resource triggered a full-table scan on all related tables (like keyword, publication, etc.) to check for orphans. This caused significant latency (measured in seconds) that would have become a major bottleneck as the database scaled.

The Solution

  1. Targeted Triggers: Moved orphan deletion logic from the main resource tables to the many-to-many link tables. Triggers now only verify the specific items that were just unlinked.
  2. Database Indexing: Added index=True to the linked_identifier column in all dynamically generated many-to-many link tables.
  3. Efficiency: Reduced the orphan check complexity from O(N) (whole table scan) to O(1) (indexed lookup).

@shreyanshsingh1234-dev shreyanshsingh1234-dev changed the title optimize delete trigger fix: Deleting an asset is very slow Feb 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant