-
Notifications
You must be signed in to change notification settings - Fork 87
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
#569: Don't create empty translations on read #668
base: master
Are you sure you want to change the base?
Conversation
Hmm... might not be as simple. In this case if you first do a read, it'll cache the read as the isolated record. Then subsequent writes will go to the isolated record instead of the built one, and they won't save. Let me try to fix. |
Should be fixed now! |
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.
Thanks for doing this work! I can see that this fixes the problem for your use case. The problem as I note above is that it also will create new instances on every read, which could be a problem.
I suggested another solution which, while not as easy to implement, is the right solution IMO. It might be too much to ask but if someone wants to ship this fix, that's the solution I would accept. However, since that would also change fundamentally how the backend works, it may have an impact on other things and need to be shipped at least in a minor release rather than a patch release.
<module fileurl="file://$PROJECT_DIR$/.idea/mobility.iml" filepath="$PROJECT_DIR$/.idea/mobility.iml" /> | ||
</modules> | ||
</component> | ||
</project> |
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.
Can you remove this?
if for_read | ||
return translations.klass.new(locale: locale) if translation.nil? | ||
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 will repeatedly create instances on each read, which could be a problem in some hot spots.
I think a better approach would be to replace the build
with an array of instances created with new
(as you have above) rather than build
, so that they are not saved by default.
Then we would need to add a save hook to assign the instances before saving. I believe this is how Globalize does it.
Fixes #569 .
This ended up being simpler than I expected. I simply added a
for_read
parameter that's only set on read, which would return an isolated translation object instead of one attached to thetranslations
collection. This leaves the cache intact as well.