def user_email_for_activity(activity)
      return activity.user if activity.user.is_a?(String)

      @user_emails ||= begin
        User.select([:id, :email]).all.each_with_object({}) do |user, hash|
          hash[user.id] = user.email
        end
      end
      @user_emails[activity.user_id]
    end
def user_email_for_activity(activity)
      return activity.user if activity.user.is_a?(String)

      @user_emails ||= begin
        User.select([:id, :email]).all.each_with_object({}) do |user, hash|
          hash[user.id] = user.email
        end
      end
      @user_emails[activity.user_id]
    end
Cache user emails so we don't have to make an extra SQL request
 for every activity