-
Notifications
You must be signed in to change notification settings - Fork 92
Simply return value after write in active_record container backend
#671
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
base: master
Are you sure you want to change the base?
Conversation
This fixes a bug where `#read` is overwritten by the cache plugin and therefore the container backend returns stale data. It should always return the value it wrote. Since `value` is never modified by this backend it makes no sense to read it again after setting it. Besides fixing the bug it might give a small perfomance boost, too. fixes https://github.com/shioyama/mobility/pull/543/files#r1944637671 thanks @dramalho for uncovering the bug and hints
|
Lovely, thank you |
|
|
||
| expect { post.title = 'aaa' }.to change { post.title }.from(nil).to('aaa') | ||
| 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.
Thank you for including a test!
|
This seems reasonable to me, my only concern with returning |
050d333 to
d06c738
Compare
d06c738 to
790d77c
Compare
I don't think this is how ruby works with setters if I am correct, e.g. any setter always returns the passed in value no matter what: module Something
def self.bla
puts "calling getter"
@bla
end
def self.bla=(value)
puts "calling setter"
@bla = value
# try to return something different from setter
"something different"
end
end
Something.bla
# calling getter
# => nil
Something.bla = 'my value'
# calling setter
# => "my value"
Something.bla
# calling getter
# => "my value"Or did you think of something different? I added a spec though to check that the presence plugin is applied to the value written to the backend, e.g. it does not save |
Simply return
valueafter write in active_record container backendThis fixes a bug where
#readis overwritten by the cache plugin andtherefore the container backend returns stale data. It should always
return the value it wrote.
Since
valueis never modified by this backend it makes no sense toread it again after setting it.
Besides fixing the bug it might give a small perfomance boost, too.
fixes https://github.com/shioyama/mobility/pull/543/files#r1944637671
thanks @dramalho for uncovering the bug and hints