Created
July 11, 2011 12:57
-
-
Save durran/1075777 to your computer and use it in GitHub Desktop.
Mongoid identity map and fibers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See: https://github.com/mongoid/mongoid/blob/identity-map/spec/unit/mongoid/identity_map_spec.rb#L367 | |
# In order for the identity map to work when using fibers the | |
# entire unit of work must happen on the same fiber since it's using | |
# thread locals for storage. | |
# The following example is correct: | |
fiber = Fiber.new do | |
Person.find(id) | |
Person.find(id) # This query hits the identity map. | |
end | |
fiber.resume | |
# The following example is incorrect: | |
Person.find(id) | |
fiber = Fiber.new do | |
Person.find(id) # This query hits the database. | |
end | |
fiber.resume |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment