brianhempel/mongo_session_store

Session is loaded when Rails serves assets

Opened this issue · 7 comments

See the rails output:

Started GET "/assets/image.png" for 127.0.0.1 at 2013-04-12 21:04:44 -0400
MOPED: ip_removed:27017 COMMAND database=admin command={:ismaster=>1} (49.5179ms)
MOPED: ip_removed:27017 QUERY database=test_app collection=sessions selector={"$query"=>{"_id"=>"Ex3eCW1YUFRMj0w3FSiToazcD4Y"}, "$orderby"=>{:_id=>1}} flags=[:slave_ok] limit=-1 skip=0 batch_size=nil fields=nil (24.9338ms)
Served asset /image.png - 304 Not Modified (0ms)

If this a bug, it's probably a bug in Rails. However, it's probably not a bug at all, because ideally assets are not served through Rails in production--you offload them to a static service. I believe the option to serve assets through Rails is mostly for ease of development.

Yes I know, I only see it in development. It makes asset delivery time significantly increased. I do not see the same issue using this gem with mongoid 2. Could mongoid be the source?

On Apr 14, 2013, at 10:49 AM, Brian Hempel notifications@github.com wrote:

If this a bug, it's probably a bug in Rails. However, it's probably not a bug at all, because ideally assets are not served through Rails in production--you offload them to a static service. I believe the option to serve assets through Rails is mostly for ease of development.


Reply to this email directly or view it on GitHub.

It looks like it. Does this line appear for each asset loaded?

MOPED: ip_removed:27017 COMMAND database=admin command={:ismaster=>1} (49.5179ms)

Yes it does. Did you find something?

I was just concerned since not only does it significantly slow development speed but pure ruby servers like Unicorn or Puma could potentially see this issue in production if they have serve_static_assets on, however unlikely.

On Apr 21, 2013, at 4:25 PM, Brian Hempel notifications@github.com wrote:

It looks like it. Does this line appear for each asset loaded?

MOPED: ip_removed:27017 COMMAND database=admin command={:ismaster=>1} (49.5179ms)

Reply to this email directly or view it on GitHub.

If that extra query happens every time, it probably means that this gem might be accessing Mongo collections through Mongoid in a way that fires an extra query. I'll have to look into it sometime.

Does this have to do with Rails code reloading? In the MongoSessionStore tests, the "ismaster" COMMAND only appears at the start of the tests and is not repeated on each web request.

Also, is your development database off-site?

Its possible it has something to do with reload, but I'm not sure what that would be. It seems to be loading the session data for asset requests. Could the rack middleware be inserting itself at the wrong location?

Also, it didn't matter if the database was remote or local, only occurred in the development environment (but probably because I'm using apache for serving assets).