Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: BOM Update Tool #31072

Merged
merged 22 commits into from
Jun 9, 2022
Merged

perf: BOM Update Tool #31072

merged 22 commits into from
Jun 9, 2022

Commits on May 18, 2022

  1. perf: get_boms_in_bottom_up_order

    - Create child-parent map once and fetch value from child key to get parents
    - Get parents recursively for a leaf node (get all ancestors)
    - Approx. 44 secs for 4lakh 70k boms
    marination committed May 18, 2022
    Configuration menu
    Copy the full SHA
    b6e46ee View commit details
    Browse the repository at this point in the history

Commits on May 19, 2022

  1. fix: DB update child items, remove redundancy, fix perf

    - Move `get_boms_in_bottom_up_order` in bom update tool’s file
    - Remove repeated rm cost update from `update_cost`. `calculate_cost` handles RM cost update
    - db_update children in `calculate_cost` optionally
    - Don’t call `update_exploded_items` and regenerate exploded items in `update_cost`. They will stay the same (except cost)
    marination committed May 19, 2022
    Configuration menu
    Copy the full SHA
    5932e9d View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    9dc3083 View commit details
    Browse the repository at this point in the history
  3. perf: Use cached doc instead of get_doc

    - Doc is only used to iterate over items(which wont change) and change rate/amount of rows
    - These changes are inserted in db via `db_update`, so no harm
    - Tested locally: refetching cached doc after db update, reflects fresh data.
    marination committed May 19, 2022
    Configuration menu
    Copy the full SHA
    9a7e9d9 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    dd99c00 View commit details
    Browse the repository at this point in the history
  5. fix: test_work_order_with_non_stock_item

    - Use the right price list and currency to avoid rate conversion (1000/62.9), since rates are reset correctly now
    - Use RM rate based on Price List in BOM. Non stock item has no valuation
    marination committed May 19, 2022
    Configuration menu
    Copy the full SHA
    90d4dc0 View commit details
    Browse the repository at this point in the history

Commits on May 25, 2022

  1. feat: Level-wise BOM cost updation

    - Process BOMs level wise and Pause after level is complete
    - Cron job will resume Paused jobs, which will again process the new level and pause at the end
    - This will go on until all BOMs are updated
    - Added Progress section with fields to track updated BOMs in Log
    - Cleanup: Add BOM Updation utils file to contain helper functions/sub-functions
    - Cleanup: BOM Update Log file will only contain functions that are in direct context of the Log
    
    Co-authored-by: Gavin D'souza <gavin18d@gmail.com>
    marination and gavindsouza committed May 25, 2022
    Configuration menu
    Copy the full SHA
    ab2d95a View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    9f5f18e View commit details
    Browse the repository at this point in the history

Commits on May 27, 2022

  1. feat: Only update exploded items rate and amount

    - Generate RM-Rate map from Items table (will include subassembly items with rate)
    - Function to reset exploded item rate from above map
    - `db_update` exploded item rate only if rate is changed
    - Via Update Cost, only update exploded items rate, do not regenerate table again
    - Exploded Items are regenerated on Save and Replace BOM job
    - `calculate_exploded_cost` is run only via non doc events (Update Cost button, Update BOMs Cost Job)
    marination committed May 27, 2022
    Configuration menu
    Copy the full SHA
    eabd829 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    5949946 View commit details
    Browse the repository at this point in the history
  3. perf: get_next_higher_level_boms

    - Separate getting dependants and checking if they are valid (loop within loop led to redundant processing that slowed down function)
    - Adding to above, the same dependant(parent) was repeatedly processed as many children shared it. Expensive.
    - Use a parent-child map similar to child-parent map to check if all children are resolved
    - `map.get()` reduced time: 10 mins -> 0.9s~1 second (as compared to `get_cached_doc` or query)
    - Total time: 17 seconds to process 6599 leaf boms and 4.2L parent boms
    - Previous Total time: >10 mins (I terminated it due to not wanting to waste time XD)
    marination committed May 27, 2022
    Configuration menu
    Copy the full SHA
    2de2491 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    978ba52 View commit details
    Browse the repository at this point in the history

Commits on May 31, 2022

  1. chore: Limit Update Cost jobs & db_update only if changed values

    - If `Update Cost` job is ongoing, then block creation of new ones since all BOMs are updated
    - `db_update` in `calculate_rm_cost` only if changed values to reduce redundant row updates
    - Misc: Use variable for batch size
    marination committed May 31, 2022
    Configuration menu
    Copy the full SHA
    a62bc9b View commit details
    Browse the repository at this point in the history

Commits on Jun 2, 2022

  1. feat: Track progress in Log Batch/Job wise

    - This was done due to stale reads while the background jobs tried updating status of the log
    - Added a table where all bom jobs within log will be tracked with what level they are processing
    - Cron job will check if table jobs are all processed every 5 mins
    - If yes, it will prepare parents and call `process_boms_cost_level_wise` to start next level
    - If pending jobs, do nothing
    - Current BOM Level is being tracked that helps adding rows to the table
    - Individual bom cost jobs (that are queued) will process and update boms > will update BOM Update Batch table row with list of updated BOMs
    marination committed Jun 2, 2022
    Configuration menu
    Copy the full SHA
    62857e3 View commit details
    Browse the repository at this point in the history

Commits on Jun 6, 2022

  1. chore: Miscellanous fixes/enhancements

    - `get_valuation_rate`: if no bins are found return 0, SLEs do not exist either
    - `get_valuation_rate`: Compute average valuation rate via query
    - `get_rm_rate_map`: set order_by as None to avoid creating sort index (modified) each time query runs (seen in process list)
    - BOM Update Batch: add status field and hide `boms_updated` so that  users can see progress without loading all updated boms (too much data)
    - BOM Update Batch: set batch row status to completed after job runs
    - BOM Update Log: remove `parent_boms` field (just pass parent boms to processing function) & remove Paused state (not used)
    - Move job to long queue to avoid choking default queue
    - `update_cost_in_boms`: use `get_doc` as each BOM is accessed only once. Use `for_update` to lock BOM row
    - Commit after every 100 BOMs
    marination committed Jun 6, 2022
    Configuration menu
    Copy the full SHA
    934db57 View commit details
    Browse the repository at this point in the history
  2. chore: get_valuation_rate in bom.py must always return float & goto…

    … Item master if no bins
    marination committed Jun 6, 2022
    Configuration menu
    Copy the full SHA
    1510119 View commit details
    Browse the repository at this point in the history

Commits on Jun 7, 2022

  1. test: Util to update cost in all BOMs

    - Utility to update cost in all BOMs without cron jobs or background jobs (run immediately)
    - Re-use util wherever all bom costs are to be updated
    - Skip explicit commits if in test
    - Specify company in test records (dirty data sometimes, company wh mismatch)
    - Skip background jobs queueing if in test
    marination committed Jun 7, 2022
    Configuration menu
    Copy the full SHA
    6bde1bb View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    ff0a6b7 View commit details
    Browse the repository at this point in the history

Commits on Jun 8, 2022

  1. test: Fix test_update_bom_cost_in_all_boms

    - Use base_rate for assertions as rate is subject to change due to conversion factor (USD)
    marination committed Jun 8, 2022
    Configuration menu
    Copy the full SHA
    9f2793c View commit details
    Browse the repository at this point in the history
  2. chore: get_valuation_rate sider fixes

    - Use qb instead of db.sql
    - Don't use `args` as argument for function
    - Cleaner variable names
    marination committed Jun 8, 2022
    Configuration menu
    Copy the full SHA
    7e41d84 View commit details
    Browse the repository at this point in the history

Commits on Jun 9, 2022

  1. Configuration menu
    Copy the full SHA
    a6edce2 View commit details
    Browse the repository at this point in the history
  2. chore: Less hacky tests, versioning (replace bom) and clearing log da…

    …ta (update cost)
    
    - Remove `auto_commit_on_many_writes` in `update_cost_in_level()` as commits happen every N BOMs
    - Auto commit every 50 BOMs
    - test: Remove hacky `frappe.flags.in_test` returns
    - test: Enqueue `now` if in tests (for update cost and replace bom)
    - Replace BOM: Copy bom object to `_doc_before_save` so that version.py finds a difference between the two
    - Replace BOM: Add reference to version
    - Update Cost: Unset `processed_boms` if Log is completed (useless after completion)
    - test: `update_cost_in_all_boms_in_test` works close to actual prod implementation (only call Cron job manually)
    - Test: use `enqueue_replace_bom`  so that test works closest to production behaviour
    
    Co-authored-by: Ankush Menat <ankushmenat@gmail.com>
    marination and ankush committed Jun 9, 2022
    Configuration menu
    Copy the full SHA
    3fa0a46 View commit details
    Browse the repository at this point in the history