Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-2364

API to store current session in thread-local storage

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Trivial - P5 Trivial - P5
    • None
    • Affects Version/s: None
    • Component/s: Dev Exp, Sessions
    • Labels:
      None

      Currently, with_session is called on Document class and instance. Examples:

      Person.with_session { Person.all.first; Car.all.to_a,first; Dog.all.first }
      # or
      bob = Person.new
      bob.with_session { ... }
      

      This syntax is very awkward, because you must call "with_session" on one document, but then you can call other documents in the same scope as long as they share the same client. It would be much more intuitive if we called it on the Mongo::Client instead, which is the fundamental "isolation unit" of the session.

      Mongoid.clients['default'].with_session { ... }
      # or
      Person.persistence_context.client.with_session { ... }
      

      (We could keep the existing syntax as well).

      This change would require added thread storage to Mongo library. Alternatively, we could add a face Mongoid::Client which subclasses/wraps Mongo::Client and adds this method. This might make things a lot cleaner, as it is also awkward that Mongoid::Clients is an array of Mongo::Client.

            Assignee:
            Unassigned Unassigned
            Reporter:
            shields@tablecheck.com Johnny Shields
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: