feat(category): faster removal#18521
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves the performance of category removal by batching post-delete side effects (stats recalculation and linked-component alert refresh) and by avoiding work for components that are also being removed, which is especially important when a category contains many linked components.
Changes:
- Introduces
RemovalBatchto deduplicate and defer stats updates + linked componentupdate_alerts()until transaction commit. - Refactors component/category removal tasks to support batched removals and skip propagation updates for components being removed.
- Adds regression tests around batching behavior and documents the user-visible improvement in the changelog.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
weblate/trans/tasks.py |
Refactors removal flow into helper functions and adds batched category removal with deferred flush. |
weblate/trans/removal.py |
Adds RemovalBatch helper to collect and flush deduped updates on commit. |
weblate/trans/models/component.py |
Adds in-memory removal_batch attribute on Component instances used during deletion. |
weblate/trans/models/__init__.py |
Updates component deletion signals to batch stats/linked-alert updates when removal_batch is set. |
weblate/trans/tests/test_categories.py |
Adds tests verifying batching of linked alert refresh, skipping propagation, and batched stats updates. |
docs/changes.rst |
Adds changelog entry for faster category removal. |
9cec88c to
e8d3c3b
Compare
Collect components to be removed to better handle situations with many linked components being removed.
There was a problem hiding this comment.
Pull request overview
This PR improves the performance of category removal in Weblate by batching follow-up work (stats updates and linked-component alert refreshes) so large removals—especially with many linked components—do not trigger repetitive per-component updates.
Changes:
- Add
RemovalBatch+ contextvar plumbing to collect removed component IDs, parent stats objects, and linked-component alert refresh targets. - Refactor
category_removal(and component removal internals) to use the batch, flush once on transaction commit, and skip propagation work for components that will be removed. - Add regression tests validating batching behavior and update/propagation skipping; document the change in the changelog.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| weblate/trans/tasks.py | Refactors category removal to pre-collect removal targets and use a single batched flush for stats/alerts, while avoiding propagation scheduling for soon-to-be-removed components. |
| weblate/trans/removal.py | Introduces RemovalBatch and a context manager for batched removal side-effects flushed on commit. |
| weblate/trans/models/init.py | Updates delete signals to use the active removal batch (instance-bound or contextvar) to collect stats and linked alert refreshes instead of scheduling per-delete callbacks. |
| weblate/trans/models/component.py | Adds a non-persistent removal_batch attribute to component instances to associate deletions with a batch. |
| weblate/trans/tests/test_categories.py | Adds tests covering batched alert refresh, propagation skipping, and batched parent stats updates during category removal. |
| docs/changes.rst | Adds a changelog entry for faster category removal. |
Collect components to be removed to better handle situations with many linked components being removed.