Simply return value after write in active_record container backend#671
Simply return value after write in active_record container backend#671doits wants to merge 2 commits intoshioyama:masterfrom
value after write in active_record container backend#671Conversation
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.
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