I just upgrade to 0.10.2 and I'm seeing far more queries occurring
than with 0.10.1. I'm still investigating further but it looks like
the identity map is not being applied properly when traversing
associations. This can be seen with even the simplest test:
class User
include DataMapper::Resource
property :id, Serial
property :username, String
has n, :posts
end
class Post
include DataMapper::Resource
property :id, Serial
property :title, String
belongs_to :user
end
DataMapper::Logger.new(STDOUT, :debug)
DataMapper.setup(:default, 'sqlite3::memory:')
DataMapper.auto_migrate!
users = [User.create(:username => 'foo'), User.create(:username => 'bar')]
posts = []
1.upto(10) do |i|
posts << Post.create(:title => "Post #{i}", :user => users.pick)
end
Post.all.each do |p|
# force some traversals of the relationships
puts p.user.posts.first.user.username
puts p.user.posts.last.user.username
end
Queries under 0.10.1 (excluding CREATE/INSERT/etc.):
~ (0.000054) SELECT "id", "title", "user_id" FROM "posts" ORDER BY "id"
~ (0.000035) SELECT "id", "username" FROM "users" WHERE "id" IN (2,
1) ORDER BY "id"
~ (0.000035) SELECT "id", "title", "user_id" FROM "posts" WHERE
"user_id" IN (1, 2) ORDER BY "id"
Queries under 0.10.2 (excluding CREATE/INSERT/etc.):
~ (0.000042) SELECT "id", "title", "user_id" FROM "posts" ORDER BY "id"
~ (0.000038) SELECT "id", "username" FROM "users" WHERE "id" IN (2,
1) ORDER BY "id"
~ (0.000043) SELECT "id", "title", "user_id" FROM "posts" WHERE
"user_id" = 2 ORDER BY "id" LIMIT 1
bar
~ (0.000053) SELECT "id", "title", "user_id" FROM "posts" WHERE
"user_id" = 2 ORDER BY "id" DESC LIMIT 1
bar
bar
bar
~ (0.000066) SELECT "id", "title", "user_id" FROM "posts" WHERE
"user_id" = 1 ORDER BY "id" LIMIT 1
foo
~ (0.000049) SELECT "id", "title", "user_id" FROM "posts" WHERE
"user_id" = 1 ORDER BY "id" DESC LIMIT 1
Has anyone else seen similar behavior when moving from 0.10.1 to
0.10.2? Any workarounds or changes in 0.10.2 that I missed in the
release notes?
Thanks,
Paul
--
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en.