Skip to content

Instantly share code, notes, and snippets.

@durran
Created July 11, 2011 12:57
Show Gist options
  • Save durran/1075777 to your computer and use it in GitHub Desktop.
Save durran/1075777 to your computer and use it in GitHub Desktop.
Mongoid identity map and fibers
# 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