-
Notifications
You must be signed in to change notification settings - Fork 4
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
Filter properties in the database instead of in memory #5
Changes from 5 commits
fab25b6
bb6b98c
b80abf7
19ff64a
e441b9a
fe28690
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module RailsProperties | ||
VERSION = '3.4.3' | ||
VERSION = '4.0.0' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels like a big enough change to warrant a major version bump. |
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,7 @@ | |
user.properties(:dashboard).bar = 'string' | ||
user.properties(:calendar).bar = 'string' | ||
user.save! | ||
}.to perform_queries(3) | ||
}.to perform_queries(4) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The number of queries increases because we're not loading all of the target's property objects into memory anymore. So we have one query to get the user's |
||
end | ||
end | ||
|
||
|
@@ -94,7 +94,7 @@ | |
|
||
it "should update properties by one SQL query" do | ||
expect { | ||
user.properties(:dashboard).update_attributes! :foo => 'bar' | ||
user.properties(:dashboard).update! :foo => 'bar' | ||
}.to perform_queries(1) | ||
end | ||
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.
This memoization is being done to support new property objects. If a property object isn't in the database,
property_objects.find_or_initialize_by(var: var)
returns an new object in memory. Since we can write multiple values to a new property like#properties
needs to return the same instance of the property object. Otherwise, we'll have two different property objects for the samevar
(:portal
in the above example), and that's not allowed.This memoization was happening implicitly before when everything was being loading into memory.