don't call stale detection on each call and add flag to disable it#139
Open
kubosuke wants to merge 1 commit into
Open
don't call stale detection on each call and add flag to disable it#139kubosuke wants to merge 1 commit into
kubosuke wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request
Description
in short, performance fix around stale detector
Fixes severe performance on the translations list page (
/kanta/locales/:id/translations) when many messages exist (~22k+). The page was replying in ~45 seconds because full stale detection (load all messages, PO parsing, partitioning, fuzzy Jaro matching) ran synchronously on every mount. This PR uses the cached stale-detection result fromMessagesExtractorAgenton mount instead of callingStaleDetection.call()each time, and adds a config flag to disable stale detection entirely (no work at boot or on translations/dashboard, 0 counts in UI).example:
Type of Change
Related Issues
Fixes #
Closes #
Related to #
Changes Made
MessagesExtractorAgent.get_stale_detection_result()(cached) instead ofKanta.PoFiles.Services.StaleDetection.call(). Handlenil(e.g. before agent has run) as emptystale_message_idsandfuzzy_matches.stale_detection_assigns/0helper; whenKanta.config().disable_stale_detectionis true, assign empty MapSet and empty map and skip the agent.get_stale_detection_result(true)for refresh-after-merge/delete.disable_stale_detection: boolean()(defaultfalse) with validation.conf.disable_stale_detectionis true (pattern-matched), skipMessagesExtractorandStaleDetection.call()and setstale_detection_result: nil. Whenget_stale_detection_result(true)is called and disabled, return current state without running StaleDetection.disable_stale_detectionis true,get_stale_messages_countandget_mergeable_messages_countreturn 0 without calling the agent; "delete stale" and "restore mergeable" handlers no-op.Testing
Test Environment
Test Cases
Test Commands Run
Documentation
Code Quality
Backward Compatibility
Breaking Changes
None.
Performance Impact
Performance Notes
Before this change, loading
/kanta/locales/3/translationswith ~22,868 translations showed Replied in 45059ms while DB queries were fast. Example logs:The bottleneck was CPU work in StaleDetection (loading all messages, partitioning, fuzzy Jaro matching), not DB or cache. After the fix, the translations page uses the agent's cached result on mount, so response time should align with the ~17ms observed for
handle_paramsafter the first reply. Withdisable_stale_detection: true, no StaleDetection runs at boot or on translations/dashboard requests.Translation Management Impact
Translation Impact Notes
Translations list and dashboard use stale detection for "stale" badges and merge suggestions. With the flag enabled (default), behavior is unchanged except that the list page loads quickly. With
disable_stale_detection: true, stale/mergeable counts show as 0 and related actions are no-ops.Security Considerations
Additional Notes
Host apps can disable stale detection via Kanta config, e.g. in
config/config.exs:Ensure this config is passed to
Kanta.start_link/1(e.g. viaApplication.get_env(:my_app, Kanta, [])).Screenshots/Examples
Checklist
Reviewer Notes
handle_info(:refresh_messages)still recomputes when stale detection is enabled.init(conf: %Kanta.Config{disable_stale_detection: true})for the disabled path.