mongo_session_store icon indicating copy to clipboard operation
mongo_session_store copied to clipboard

Session is loaded when Rails serves assets

Open uranazo opened this issue 11 years ago • 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)

uranazo avatar Apr 13 '13 01:04 uranazo

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.

brianhempel avatar Apr 14 '13 14:04 brianhempel

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 [email protected] 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.

uranazo avatar Apr 14 '13 22:04 uranazo

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

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

brianhempel avatar Apr 21 '13 20:04 brianhempel

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 [email protected] 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.

uranazo avatar Apr 21 '13 21:04 uranazo

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.

brianhempel avatar Apr 21 '13 23:04 brianhempel

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?

brianhempel avatar Mar 01 '14 22:03 brianhempel

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).

mgwidmann avatar Mar 03 '14 00:03 mgwidmann