mirror of
https://github.com/osukey/osukey.git
synced 2025-06-07 04:18:04 +09:00
Fix RealmLive
failing to retrieve due to lack of refresh
This commit is contained in:
parent
d2655c0825
commit
81b5717ae7
@ -53,18 +53,7 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
realmFactory.Run(realm =>
|
realmFactory.Run(realm =>
|
||||||
{
|
{
|
||||||
var found = realm.Find<T>(ID);
|
perform(retrieveFromID(realm, ID));
|
||||||
|
|
||||||
if (found == null)
|
|
||||||
{
|
|
||||||
// It may be that we access this from the update thread before a refresh has taken place.
|
|
||||||
// To ensure that behaviour matches what we'd expect (the object *is* available), force
|
|
||||||
// a refresh to bring in any off-thread changes immediately.
|
|
||||||
realm.Refresh();
|
|
||||||
found = realm.Find<T>(ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
perform(found);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +68,7 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
return realmFactory.Run(realm =>
|
return realmFactory.Run(realm =>
|
||||||
{
|
{
|
||||||
var returnData = perform(realm.Find<T>(ID));
|
var returnData = perform(retrieveFromID(realm, ID));
|
||||||
|
|
||||||
if (returnData is RealmObjectBase realmObject && realmObject.IsManaged)
|
if (returnData is RealmObjectBase realmObject && realmObject.IsManaged)
|
||||||
throw new InvalidOperationException(@$"Managed realm objects should not exit the scope of {nameof(PerformRead)}.");
|
throw new InvalidOperationException(@$"Managed realm objects should not exit the scope of {nameof(PerformRead)}.");
|
||||||
@ -119,6 +108,22 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private T retrieveFromID(Realm realm, Guid id)
|
||||||
|
{
|
||||||
|
var found = realm.Find<T>(ID);
|
||||||
|
|
||||||
|
if (found == null)
|
||||||
|
{
|
||||||
|
// It may be that we access this from the update thread before a refresh has taken place.
|
||||||
|
// To ensure that behaviour matches what we'd expect (the object *is* available), force
|
||||||
|
// a refresh to bring in any off-thread changes immediately.
|
||||||
|
realm.Refresh();
|
||||||
|
found = realm.Find<T>(ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
public bool Equals(ILive<T>? other) => ID == other?.ID;
|
public bool Equals(ILive<T>? other) => ID == other?.ID;
|
||||||
|
|
||||||
public override string ToString() => PerformRead(i => i.ToString());
|
public override string ToString() => PerformRead(i => i.ToString());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user