1

I have this really weird behaviour in my rails application. All find queries are run double. I've verified this by logging the queries both on the ap side and on the DB side. I've only tested it in development mode though.

I've added logging to the methods to see if the methods are called multiple times, but that wasn't the case.

All saves run exactly once, so there are no problems there. Only the problem that page loads will be increasingly slower the more data there is in the DB since it queries all data twice.

I don't even know which parts of the code I should paste, since I have no clue where this could be coming from.

I'm using mongoid (3.0.13), rails (3.1.3)

Here's the link to github for the whole source https://github.com/deiga/new-Roydon/tree/develop

deiga
  • 1,587
  • 1
  • 13
  • 32

2 Answers2

9

You've probably resolved it by now, but I had the same issue and the reason was the bullet gem, which reruns every Mongoid find for the purpose of measuring the performance.

I can see that you also have it included in your Gemfile, so that's probably it.

M. Cypher
  • 6,966
  • 2
  • 34
  • 34
0

It appears that Shop::Category::all_products, which calls Ancestry's children method, is creating a Mongoid select. Meanwhile, you had already fetched the associated products in your ProductsController when you specified includes(:products).

Try removing includes(:products) from line 5 of ProductsController and see if it removes the duplication from that controller action.

platforms
  • 2,666
  • 1
  • 18
  • 23
  • Sure, I'll try it. It it wouldn't explain why all the other find's are also duplicated. I mean the ``Shop::ShoppingCart.find``and everything else too. – deiga Dec 02 '12 at 20:50
  • It might, if a similar thing was happening in the `before_filter`s in Shop::ControllerController. – platforms Dec 02 '12 at 21:21