refactor: eliminate database queries and business logic from views#4
refactor: eliminate database queries and business logic from views#4cezargf wants to merge 1 commit into
Conversation
- Moved `$this->db->count_all` queries from `painel.php` to the `Mapos` controller to prevent views from directly querying the DB. - Replaced model calls like `isEditable` within loops in `os.php` and `vendas.php` with inline evaluations using existing row data and global configurations. This resolves severe N+1 query problems. - Migrated business logic (calculating `$texto_de_notificacao` via `criarTextoWhats`) from `visualizarOs.php` and `editarOs.php` to the `Os` controller. Co-authored-by: cezargf <25113573+cezargf@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. |
There was a problem hiding this comment.
Code Review
This pull request addresses N+1 query vulnerabilities by moving database counts and editability logic from views to controllers or inline checks. It also refactors WhatsApp notification generation by moving the logic from views to the Os controller. Review feedback identifies a security regression in the os.php view due to a missing permission check, potential bugs when formatting null dates in the Os controller, and suggests further refactoring to reduce logic duplication and adhere to MVC principles.
This pull request refactors several view files to improve performance and adhere to MVC patterns. Views were making direct database queries or calling model logic inside loops, causing N+1 query inefficiencies.
Key changes:
painel.php:count_alldatabase calls were moved to theMaposcontroller.os.php&vendas.php: RemovedisEditablemodel method calls inside loops, replacing them with in-memory checks using loop variables and the automatically injected global configuration ($configuration['control_editos'],$configuration['control_edit_vendas']).visualizarOs.php&editarOs.php: Shifted the generation of$texto_de_notificacaoand$zapnumberto the controller where data formatting belongs.PR created automatically by Jules for task 2373530467167720773 started by @cezargf