Skip to content

feat(unit): apply delta of stats upon edit#18588

Open
nijel wants to merge 1 commit intoWeblateOrg:mainfrom
nijel:edit-performance
Open

feat(unit): apply delta of stats upon edit#18588
nijel wants to merge 1 commit intoWeblateOrg:mainfrom
nijel:edit-performance

Conversation

@nijel
Copy link
Member

@nijel nijel commented Mar 23, 2026

This avoids possibly expensive full stats update on large components and only applies delta that can be inferred from the current edit. The scope of delta handling is intentionally narrow to handle only the simple cases and avoid code complexity. If delta approach cannot be used, it falls back to standard stats calculation.

@nijel nijel added this to the 5.17 milestone Mar 23, 2026
@nijel nijel requested review from amCap1712 and Copilot March 23, 2026 13:41
@nijel nijel self-assigned this Mar 23, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces an incremental (“delta”) update path for translation/component statistics when editing template/source units, aiming to avoid expensive full stats rebuilds on large components while still falling back to full recomputation when the delta can’t be trusted.

Changes:

  • Add unit “snapshot” + bucketing utilities in TranslationStats to compute per-unit stat deltas.
  • Update Unit.update_source_units() to apply deltas on commit (or fall back to Component.invalidate_cache() when needed) and add a cache-invalidation suppression mechanism on Translation.
  • Add/adjust tests around stats invalidation behavior for source edits and AUTO translations.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
weblate/utils/stats.py Adds UnitSnapshot and delta/bucket helpers plus apply_source_delta() on TranslationStats.
weblate/trans/models/unit.py Refactors template source propagation to attempt delta-based stats updates; marks cases requiring full rebuild; minor cleanup.
weblate/trans/models/translation.py Adds suppress_cache_invalidation() and a flag to force full stats rebuild fallback.
weblate/trans/tests/test_edit.py Adds tests asserting cache invalidation behavior for source edits and AUTO translations.

@argos-ci
Copy link

argos-ci bot commented Mar 23, 2026

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) ⚠️ Changes detected (Review) 21 changed Mar 26, 2026, 12:31 PM

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

This avoids possibly expensive full stats update on large components and
only applies delta that can be inferred from the current edit. The scope
of delta handling is intentionally narrow to handle only the simple
cases and avoid code complexity. If delta approach cannot be used, it
falls back to standard stats calculation.
@nijel nijel force-pushed the edit-performance branch from aacf10f to 8b86172 Compare March 26, 2026 11:39
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.

Faster save when translating base language

2 participants