paginate中count自定义

WillPaginate

数据量一大起来 select count(*)as count_all from TABLE 查询真耗性能。

mysql是一个好东西啊,有些业辑项还是用nosql跑起才行。

User.paginate :page=>1这么一句话将产生两条 User Load (1.5ms) SELECT * FROM users LIMIT 0, 30 SQL (56.3ms) SELECT count(*) AS count_all FROM users

自定义下count的sql吧。 count = User.find(:first,:select=>"count(id)as count").count

d=User.paginate :page=>1,:total_entries=> count

User Load (0.9ms) SELECT * FROM users LIMIT 0, 30 User Load (72.9ms) SELECT count(id)as count FROM users LIMIT 1

或者你又知道总数的话直接写一个30吧,当然非除你是佛主,把所有的问题想明白了。

d=User.paginate :page=>1,:total_entries=> 30

User Load (0.9ms) SELECT * FROM users LIMIT 0, 30

Comments