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.
This pull request introduces several significant performance and concurrency optimizations to the
frappe_optimizationsapp, focusing on reducing database load, preventing deadlocks, and improving efficiency in coupon code usage, pricing rule retrieval, and subscription processing. It also updates editor and codebase configuration for consistency.Performance and Concurrency Optimizations:
Replaces ORM-based coupon usage counter updates with direct SQL operations, ensuring atomicity and adding an exponential backoff retry mechanism to handle deadlocks gracefully. This greatly reduces race conditions and deadlocks during high-concurrency purchase flows.
Implements Redis caching for the pricing rule count to avoid repeated database queries, with cache invalidation hooks on insert/delete events. This results in sub-millisecond response times for pricing rule checks and drastically lowers database load.
Overrides the Subscription doctype to cache the current invoice in-memory per request and replaces database-level sorting with efficient in-Python sorting. This reduces redundant queries and SQL overhead during invoice generation and subscription processing.
Configuration and Documentation:
Adds a patch to set the sales update frequency to "Monthly" in Selling Settings, reducing deadlocks during bulk sales invoice submissions by batching updates. [1] [2] [3]
Updates
.editorconfigto enforce consistent indentation and line length settings for Python, JS, and frontend files, promoting codebase consistency.