2 ms·
You should use "User.count", which will do something like "select count(*) from users". "Users.all.count" will needlessly read in all users into memory and the
by kaffeinecoma 13y ago
You should use "User.count", which will do something like "select count(*) from users".
"Users.all.count" will needlessly read in all users into memory and then return a count. That might work OK for 1000 users, but beyond that?
- AznHisoka 13y agoYup. But even that takes a long time to run in Postgres if you got millions of rows. I usually run User.last.id - User.first.id, and that usually gives me the # of rows (give or take)