mirror of
https://github.com/osukey/osukey.git
synced 2025-07-03 01:09:57 +09:00
Pause imports during active gameplay
This commit is contained in:
@ -8,6 +8,7 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Humanizer;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
using osu.Framework.Logging;
|
||||
@ -56,6 +57,11 @@ namespace osu.Game.Database
|
||||
/// </summary>
|
||||
private static readonly ThreadedTaskScheduler import_scheduler_batch = new ThreadedTaskScheduler(import_queue_request_concurrency, nameof(RealmArchiveModelImporter<TModel>));
|
||||
|
||||
/// <summary>
|
||||
/// Temporarily pause imports to avoid performance overheads affecting gameplay scenarios.
|
||||
/// </summary>
|
||||
public readonly BindableBool PauseImports = new BindableBool();
|
||||
|
||||
public abstract IEnumerable<string> HandledExtensions { get; }
|
||||
|
||||
protected readonly RealmFileStore Files;
|
||||
@ -253,7 +259,7 @@ namespace osu.Game.Database
|
||||
/// <param name="cancellationToken">An optional cancellation token.</param>
|
||||
public virtual Live<TModel>? ImportModel(TModel item, ArchiveReader? archive = null, ImportParameters parameters = default, CancellationToken cancellationToken = default) => Realm.Run(realm =>
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
pauseIfNecessary(cancellationToken);
|
||||
|
||||
TModel? existing;
|
||||
|
||||
@ -551,6 +557,22 @@ namespace osu.Game.Database
|
||||
/// <returns>Whether to perform deletion.</returns>
|
||||
protected virtual bool ShouldDeleteArchive(string path) => false;
|
||||
|
||||
private void pauseIfNecessary(CancellationToken cancellationToken)
|
||||
{
|
||||
if (!PauseImports.Value)
|
||||
return;
|
||||
|
||||
Logger.Log(@"Import is being paused.");
|
||||
|
||||
while (PauseImports.Value)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
|
||||
Logger.Log(@"Import is being resumed.");
|
||||
}
|
||||
|
||||
private IEnumerable<string> getIDs(IEnumerable<INamedFile> files)
|
||||
{
|
||||
foreach (var f in files.OrderBy(f => f.Filename))
|
||||
|
Reference in New Issue
Block a user