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/PSD-3232-SCPN-product_controler_refactoring #3498

Merged
merged 1 commit into from
Jan 6, 2025

Conversation

mirotriad
Copy link
Contributor

Optimize Performance of Product Controller's Show and Update Methods

Summary

This PR improves the performance of the ResponsiblePersons::Notifications::ProductController by optimizing database queries in both show and update methods. The changes reduce unnecessary database loads and minimize query count while maintaining existing functionality.

Key Changes

Show Method Optimization

  • Reduced query count from 4+ to 1-3 queries for the completed step
  • Implemented selective association loading based on the current step
  • Added performance test to ensure query count stays within acceptable limits

Update Method Optimization

  • Reduced query count from 4+ to 2 queries for simple updates
  • Added direct column updates using update_column for simple attribute changes:
    • product_name updates
    • under_three_years updates
  • Implemented selective association loading in set_notification_and_authorize:
    • Only loads nano_materials and components for steps that need them
    • Only loads components for the single_or_multi_component step
    • No association loading for simple updates

Code Organization

  • Improved code maintainability by organizing related operations
  • Added database transactions for atomic operations
  • Added performance tests to prevent query count regression

Performance Improvements

  • Simple updates (e.g., product name changes): Reduced from 4+ to 2 queries
  • Show method completed step: Reduced to maximum 3 queries
  • Eliminated unnecessary association loading for steps that don't need them

Testing

  • Added performance-specific tests to monitor query count
  • All existing functionality tests remain passing
  • New tests ensure query counts stay within expected limits

Notes

  • No changes to existing business logic or validation rules
  • Maintains all security checks and authorization flows
  • Backwards compatible with existing API contracts

@alan-at-work alan-at-work force-pushed the perf/PSD-3232-SCPN-product_controler_refactoring branch from 6c60457 to d1d3d58 Compare December 31, 2024 09:22
@meeravnagesh meeravnagesh force-pushed the perf/PSD-3232-SCPN-product_controler_refactoring branch from 6f3aee9 to 12dfbf9 Compare January 6, 2025 12:05
@mirotriad mirotriad force-pushed the perf/PSD-3232-SCPN-product_controler_refactoring branch from ca3e742 to 405a9c5 Compare January 6, 2025 14:15
@mirotriad mirotriad merged commit 6e85e4f into main Jan 6, 2025
4 checks passed
@mirotriad mirotriad deleted the perf/PSD-3232-SCPN-product_controler_refactoring branch January 6, 2025 16:21
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.

3 participants