Mongoid queries are fast but converting to results takes time
Mongoid queries are fast. For example if it a query which returns 300 documents takes about 10 miliseconds but if I do
to_a or entries to ge开发者_开发百科t the results takes time.
Is there any other way to reduce the time lag.
I haven't look at the source code yet, but Mongoid queries are lazily evaluated.
Which means, your first call to the criteria does not touch the database, and Mongoid actually really fetch the data when you do 'to_a' or 'entries' hence the time lag.
精彩评论