Refine data center controller: ensure only active users included in t…#1080
Open
Refine data center controller: ensure only active users included in t…#1080
Conversation
…icket and base scope queries.
…om ticket and base scope queries.
…ers by filtering `team.users` appropriately.
There was a problem hiding this comment.
Pull Request Overview
This pull request refines the DataCenterController to ensure only active users are considered when processing tickets for daily reports and team email notifications. This prevents inactive users from receiving notifications and ensures ticket filtering excludes inactive user associations.
- Filters active users when collecting HOD (Head of Department) emails for daily reports
- Restricts daily report processing to only active team users
- Limits team ticket email sending to active users only
| end.order('add_statuses.updated_at DESC') | ||
|
|
||
| hod_emails = team.users.select { |u| u.has_role?(:hod) }.map(&:email) | ||
| hod_emails = team.users.where(active: true).select { |u| u.has_role?(:hod) }.map(&:email) |
There was a problem hiding this comment.
The query loads all active users into memory before filtering for HOD role. Consider using a database query to filter both conditions: team.users.joins(:roles).where(active: true, roles: { name: 'hod' }).pluck(:email) to avoid the N+1 query pattern and reduce memory usage.
Suggested change
| hod_emails = team.users.where(active: true).select { |u| u.has_role?(:hod) }.map(&:email) | |
| hod_emails = team.users.joins(:roles).where(active: true, roles: { name: 'hod' }).pluck(:email) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…icket and base scope queries.
This pull request makes targeted improvements to ticket filtering in the
DataCenterControllerby ensuring only active users are considered in relevant queries. This helps prevent tickets associated with inactive users from appearing in daily reports and team ticket emails.Ticket filtering improvements:
daily_reportmethod to filter tickets so that only those associated with active users are included.send_team_ticket_emailsmethod to ensure only active users are considered when fetching tickets for email notifications.