erpnext icon indicating copy to clipboard operation
erpnext copied to clipboard

perf: Moved `Authorization Control` Controller Logic To Utilities

Open Abdeali099 opened this issue 10 months ago • 1 comments

Moved Authorization Control controller logic to utilities

Problem:

  • Authorization Control was a DocType with no fields.
  • It was inheriting from TransactionBase, but there was no use of it.

Solution:

  • Removed the DocType Authorization Control.
  • Removed inheritance and class.
  • Imported the function in usage files:
    from erpnext.utilities.authorization_control import validate_approving_authority
    
  • Used the function instead of get_doc("Authorization Control"):
    - frappe.get_doc("Authorization Control").validate_approving_authority()
    + validate_approving_authority()
    
  • Patch:
    execute: frappe.delete_doc_if_exists("DocType", "Authorization Control")
    

Performance Improvements:

Quotation Submission

(Local cache disabled to replicate server scenario)

Before
In [5]: %timeit d.on_submit()
953 µs ± 146 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
After (73% better)
In [4]: %timeit d.on_submit()
252 µs ± 5.89 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
  • No extra DB call to get doc values during transaction submission
  • No overhead of DocType meta
  • No need to initialize

Abdeali099 avatar Mar 28 '24 11:03 Abdeali099

@Abdeali099 can you add some numbers in description

ankush avatar Mar 28 '24 12:03 ankush