mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 00:40:09 +09:00
Correctly rollback failed imports
This commit is contained in:
@ -58,13 +58,20 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
private readonly List<Action> cachedEvents = new List<Action>();
|
private readonly List<Action> cachedEvents = new List<Action>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Allows delaying of outwards events until an operation is confirmed (at a database level).
|
||||||
|
/// </summary>
|
||||||
private bool delayingEvents;
|
private bool delayingEvents;
|
||||||
|
|
||||||
private void cacheEvents()
|
/// <summary>
|
||||||
{
|
/// Begin delaying outwards events.
|
||||||
delayingEvents = true;
|
/// </summary>
|
||||||
}
|
private void delayEvents() => delayingEvents = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Flush delayed events and disable delaying.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="perform">Whether the flushed events should be performed.</param>
|
||||||
private void flushEvents(bool perform)
|
private void flushEvents(bool perform)
|
||||||
{
|
{
|
||||||
if (perform)
|
if (perform)
|
||||||
@ -167,8 +174,8 @@ namespace osu.Game.Database
|
|||||||
/// <param name="archive">The archive to be imported.</param>
|
/// <param name="archive">The archive to be imported.</param>
|
||||||
public TModel Import(ArchiveReader archive)
|
public TModel Import(ArchiveReader archive)
|
||||||
{
|
{
|
||||||
TModel item = null;
|
TModel item;
|
||||||
cacheEvents();
|
delayEvents();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -196,6 +203,7 @@ namespace osu.Game.Database
|
|||||||
item = null;
|
item = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// we only want to flush events after we've confirmed the write context didn't have any errors.
|
||||||
flushEvents(item != null);
|
flushEvents(item != null);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user