⚡ Bolt: [performance improvement] optimize remover_produto existence check#78
⚡ Bolt: [performance improvement] optimize remover_produto existence check#78rauhmaru wants to merge 1 commit into
Conversation
…check Co-authored-by: rauhmaru <2289237+rauhmaru@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What
Replaced a full table scan and a nested python-side iteration loop within
remover_produtowith TinyDB's native.contains()combined with a.any()query.🎯 Why
When deleting a product, the application needs to ensure the product isn't actively being used as an ingredient in any saved cocktail recipe. Previously, this meant calling
cocktails_table.all()(loading the entire table into memory) and manually scanning every nested ingredient array in Python to look for the ID.This
O(N * M)operation is memory-intensive and slow, especially as the cocktail table grows. TinyDB supports querying within nested lists.📊 Impact
Changes the check from an
O(N * M)full-table Python-side scan into an optimized TinyDB internal check that immediately short-circuits (O(1)toO(K)) upon finding the very first match. This reduces memory allocations (no longer returning all documents to the application layer) and speeds up the API endpoint for valid and blocked deletions.🔬 Measurement
Tests pass smoothly (
python -m pytest test_app.py). Tested existence validation by seeding mock data.PR created automatically by Jules for task 8303818743258221029 started by @rauhmaru