-
Notifications
You must be signed in to change notification settings - Fork 157
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
Obviate long-lived transactions in data binding #647
Comments
Does it auto-close it? I suggested a few days ago that I'd like an option which created a write transaction in the setter call that lived long enough to write the value. I think that needs to be an explicit mode people set - I'd be very worried about something creating write transactions invisibly by default because of the potential for clashes. In particular, any kind of auto-transaction on a thread needs to close ASAP to avoid clashing. |
As a general goal, yes I want us to deliver data binding with the least possible code especially anything varying from XAML-based idioms. |
Yes, the
where |
Works for me. All we need to do is add UWP and a lot of people will be happy! |
How does this align with moving away from RealmObject as a parent? What is the relative priority? |
I believe it's something we want sooner rather than later, as it makes it easier to use two-way databinding in Xamarin.Forms apps, especially when you drill down into relationships. |
I justed asked about this issue on StackOverflow: http://stackoverflow.com/questions/38394180/realm-mvcc-and-long-running-transactions One possible solution is to add a Realm.Unmanage() method which does the opposite of Realm.Manage() ...i.e it would copy the current values from the database to the backing fields, then "release" the object so that setting properties outside a transaction does not fail. Later you can call Realm.Manage() again to save the current values. With that in place, data binding would go as follows:
For convenience we might even have a Realm.Save() method which takes an unmanaged object, calls Realm.Manage() in a write transaction, then calls Realm.Unmanage() again so it can keep being used in a data-binding scenario. Food for thought! |
@fealebenpae just pointed out this issue should be accomplished by implementing I think my impression of it needing weaving work was from an earlier idea I had about this being done after or concurrently with moving from |
From discussions in our Engineering (internal) Slack channel, we should also be aiming to reduce the number of transactions between the oldest and latest Write or (implicit) Read transactions in a The core calls that cull old read transactions are |
One reason for reducing the priority of this issue is that it loses the ability to implement a Cancel button by simply aborting a transaction. If we commit per binding change, rollback requires a separate copy somewhere. |
I'd like some clarity on this issue as I feel it may effect me in the somewhat near future. I rely heavily on Mvvm (MvvmCross) in my Xamarin projects that use Realm. Currently I've only made databindings to Does this mean that an exception will occur at this point because it's not in a write transaction? Do I need to have an intermediary object and bind to that instead and then sync that object with the Realm database every so often. Maybe use something like AutoMapper? |
Implemented in #901 |
Note from testing in 2018, the way bindings are currently working, the setter is called per-character typed into a field, so this is generating a lot of transactions. |
This actually depends on the |
In order for MVVM data binding in XAML to work we need to keep around a write transaction so that setters invoked by binding will execute.
However, long-lived transactions have a serious drawback in that they block writes on other threads or nested writes. We do not want the property setters on a
RealmObject
to be smart enough to create implicit write transactions as that would be a performance hit in all other cases save data binding.I propose that we make
RealmObject
implementSystem.Reflection.IReflectableType
, which Xamarin.Forms respects, so that the customPropertyInfo
instances our implementation yields would be smart enough to open a write transaction if there is none. This would simplify the architecture of MVVM apps using Realm by removing the need for the long-lived transaction pattern without incurring any performance penalties for uses ofRealmObject
in cases other than data binding.The text was updated successfully, but these errors were encountered: