How to get a count of all rows

In rails when using heroku plans you sometimes run into limits and to find out which is the real memory hog you can run the following query:

ActiveRecord::Base.connection.tables.map { |t| {t=>  ActiveRecord::Base.connection.execute("select count(*) from #{t}")[0]} }

Last Updated: 29/10/2023

Published: 29/10/2023