Skip to content

Refine data center controller: ensure only active users included in t…#1080

Open
ger619 wants to merge 3 commits intodevfrom
fixed-changesofix
Open

Refine data center controller: ensure only active users included in t…#1080
ger619 wants to merge 3 commits intodevfrom
fixed-changesofix

Conversation

@ger619
Copy link
Copy Markdown
Owner

@ger619 ger619 commented Aug 11, 2025

…icket and base scope queries.
This pull request makes targeted improvements to ticket filtering in the DataCenterController by 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:

  • Updated the daily_report method to filter tickets so that only those associated with active users are included.
  • Modified the send_team_ticket_emails method to ensure only active users are considered when fetching tickets for email notifications.

@ger619 ger619 requested a review from Copilot August 11, 2025 13:52
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link

Copilot AI Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copilot uses AI. Check for mistakes.
@ger619 ger619 requested a review from Kanyorok August 11, 2025 13:59
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.

2 participants