We were trying to find records of outbound email to a user, but they only show up when you explicitly search for group_smtp
emails. This is counterintuitive and confusing for the admin:
^ you can see here a normal search for jose shows normal results
^ but a search for brian returns nothing
^ until you search with email type: group_smtp
class Admin::EmailController < Admin::AdminController
def sent
email_logs = EmailLog.joins(<<~SQL)
LEFT JOIN post_reply_keys
ON post_reply_keys.post_id = email_logs.post_id
AND post_reply_keys.user_id = email_logs.user_id
SQL
email_logs = filter_logs(email_logs, params, include_ccs: params[:type] == "group_smtp")
I suspect this is only here as an attempted query optimisation but I don’t think it’s necessary; it only creates this unexpected situation.