Skip to content

Conversation

@zeel-codder
Copy link
Collaborator

This pull request introduces several significant performance and concurrency optimizations to the frappe_optimizations app, 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:

  • Atomic and Retry-Safe Coupon Code Updates:
    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.
  • Redis-Based Caching for Pricing Rules:
    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.
  • Optimized Subscription Invoice Access:
    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:

  • Sales Update Frequency Patch:
    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]
  • EditorConfig Improvements:
    Updates .editorconfig to enforce consistent indentation and line length settings for Python, JS, and frontend files, promoting codebase consistency.

@zeel-codder zeel-codder merged commit cf10d35 into develop Dec 15, 2025
1 check passed
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.

2 participants