I came across this answer for speeding up a query, saying to use
SELECT COUNT(*) FROM (SELECT DISTINCT column_name FROM table_name) AS temp;
instead of
COUNT(DISTINCT column_name)
How would one go about writing this change in activerecord (short of just writing as an sql statement)?