mongomatic icon indicating copy to clipboard operation
mongomatic copied to clipboard

"count" takes a very long time

Open thbar opened this issue 14 years ago • 4 comments

Hello,

I just noticed (thanks to my growing base!) that for a given Item < Mongomatic::Base, Item.count will take a long time (37 seconds in my example). After browsing the code I suspect that count is going through all the documents to count them (count is doing find.count).

Using Item.collection.count instead is very fast.

I'm currently using Mongomatic 0.5.8.

thbar avatar Jan 07 '11 20:01 thbar

Yep, you should use .collection.count, bugfix will be forthcoming so that .count uses that too.

benmyles avatar Jan 07 '11 20:01 benmyles

In the mean time, a simple doc patch is enough if you prefer :)

Thanks for your work on Mongomatic!

thbar avatar Jan 07 '11 20:01 thbar

@benmyles what was the suggested fix for this?

jsmestad avatar Apr 06 '11 18:04 jsmestad

@jsmestad: looking at the code quickly I believe the fix is still to use .collection.count directly.

thbar avatar Apr 06 '11 18:04 thbar