-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure ids of resulting records are integers. #137
Conversation
@@ -67,3 +67,9 @@ class Comment < Ohm::Model | |||
|
|||
assert_equal 0, Ohm.redis.call("EXISTS", p.key[:comments]) | |||
end | |||
|
|||
test "converts ids of resulting records to integers " do |post, c1, c2, c3| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is another test to ensure that newly created models have an integer ID, so I think this could be rewritten to something like:
test "..." do |post, *comments|
assert comments.map(&:id) == post.comments.map(&:id)
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change it, but I would like to finish our discussion about this. Ping me if you're in IRC 😄
@djanowski done, please review again 😄 |
Related #130 |
Yep +1
|
I'm not 100% sure about converting ids to integers. I know it is convenient, but what makes me wonder if it's the right choice is the fact that we eventually convert every id to a string when we send it to Redis, so we pay the (very small) performance penalty twice. I checked how much slower it is to map to integers and it's more than ten times slower than just returning strings. That said, the time it takes to convert an array of a hundred strings is tiny. On the other hand, I like the idea of making |
Maybe I can go back to my first implementation. data.each_with_index do |atts, idx|
+ result << model.new(Utils.dict(atts).update(:id => ids[idx].to_i))
- result << model.new(Utils.dict(atts).update(:id => ids[idx]))
end At least, this ensures that the records have integer ids. The #ids methods still return an array of strings so I guess there's no performance penalty. wdyt? |
I'm +1 on making Maybe it's better to always ensure it's a string? (In the past, when we used What do you think? |
👍 to making |
@djanowski Right now we would have to change one line in save.lua, as it returns the id as an integer. Tiny change. |
@soveran so, 👍? :p |
Closing in favor of #141 |
Before:
After