Remove `async` from `Populate` method

This commit is contained in:
Dean Herbert 2022-01-13 16:27:07 +09:00
parent 70c107b434
commit bdb2979b2e
4 changed files with 9 additions and 18 deletions

View File

@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
using osu.Framework.Logging;
using osu.Framework.Platform;
@ -55,7 +54,7 @@ public ScoreModelManager(RulesetStore rulesets, Func<BeatmapManager> beatmaps, S
public Score GetScore(ScoreInfo score) => new LegacyDatabasedScore(score, rulesets, beatmaps(), Files.Store);
protected override Task Populate(ScoreInfo model, ArchiveReader? archive, Realm realm, CancellationToken cancellationToken = default)
protected override void Populate(ScoreInfo model, ArchiveReader? archive, Realm realm, CancellationToken cancellationToken = default)
{
// Ensure the beatmap is not detached.
if (!model.BeatmapInfo.IsManaged)
@ -66,8 +65,6 @@ protected override Task Populate(ScoreInfo model, ArchiveReader? archive, Realm
if (string.IsNullOrEmpty(model.StatisticsJson))
model.StatisticsJson = JsonConvert.SerializeObject(model.Statistics);
return Task.CompletedTask;
}
public override bool IsAvailableLocally(ScoreInfo model)

View File

@ -7,7 +7,6 @@
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
using osu.Framework.Logging;
using osu.Framework.Platform;
@ -49,7 +48,7 @@ public SkinModelManager(Storage storage, RealmContextFactory contextFactory, Gam
protected override bool HasCustomHashFunction => true;
protected override Task Populate(SkinInfo model, ArchiveReader? archive, Realm realm, CancellationToken cancellationToken = default)
protected override void Populate(SkinInfo model, ArchiveReader? archive, Realm realm, CancellationToken cancellationToken = default)
{
var skinInfoFile = model.Files.SingleOrDefault(f => f.Filename == skin_info_file);
@ -83,8 +82,6 @@ protected override Task Populate(SkinInfo model, ArchiveReader? archive, Realm r
model.InstantiationInfo = createInstance(model).GetType().GetInvariantInstantiationInfo();
checkSkinIniMetadata(model, realm);
return Task.CompletedTask;
}
private void checkSkinIniMetadata(SkinInfo item, Realm realm)

View File

@ -6,7 +6,6 @@
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using osu.Framework.Audio.Track;
using osu.Framework.Extensions;
using osu.Framework.Extensions.IEnumerableExtensions;
@ -53,7 +52,7 @@ protected BeatmapImporter(RealmContextFactory contextFactory, Storage storage, B
protected override bool ShouldDeleteArchive(string path) => Path.GetExtension(path).ToLowerInvariant() == ".osz";
protected override Task Populate(BeatmapSetInfo beatmapSet, ArchiveReader? archive, Realm realm, CancellationToken cancellationToken = default)
protected override void Populate(BeatmapSetInfo beatmapSet, ArchiveReader? archive, Realm realm, CancellationToken cancellationToken = default)
{
if (archive != null)
beatmapSet.Beatmaps.AddRange(createBeatmapDifficulties(beatmapSet.Files, realm));
@ -87,8 +86,6 @@ protected override Task Populate(BeatmapSetInfo beatmapSet, ArchiveReader? archi
LogForModel(beatmapSet, "Disassociating beatmap set ID due to loss of all beatmap IDs");
}
}
return Task.CompletedTask;
}
protected override void PreImport(BeatmapSetInfo beatmapSet, Realm realm)

View File

@ -318,7 +318,7 @@ protected virtual string ComputeHash(TModel item)
/// <param name="archive">An optional archive to use for model population.</param>
/// <param name="lowPriority">Whether this is a low priority import.</param>
/// <param name="cancellationToken">An optional cancellation token.</param>
public virtual async Task<ILive<TModel>?> Import(TModel item, ArchiveReader? archive = null, bool lowPriority = false, CancellationToken cancellationToken = default)
public virtual Task<ILive<TModel>?> Import(TModel item, ArchiveReader? archive = null, bool lowPriority = false, CancellationToken cancellationToken = default)
{
using (var realm = ContextFactory.CreateContext())
{
@ -352,7 +352,7 @@ protected virtual string ComputeHash(TModel item)
transaction.Commit();
}
return existing.ToLive(ContextFactory);
return Task.FromResult((ILive<TModel>?)existing.ToLive(ContextFactory));
}
LogForModel(item, @"Found existing (optimised) but failed pre-check.");
@ -373,7 +373,7 @@ protected virtual string ComputeHash(TModel item)
item.Hash = ComputeHash(item);
// TODO: we may want to run this outside of the transaction.
await Populate(item, archive, realm, cancellationToken).ConfigureAwait(false);
Populate(item, archive, realm, cancellationToken);
if (!checkedExisting)
existing = CheckForExisting(item, realm);
@ -387,7 +387,7 @@ protected virtual string ComputeHash(TModel item)
existing.DeletePending = false;
transaction.Commit();
return existing.ToLive(ContextFactory);
return Task.FromResult((ILive<TModel>?)existing.ToLive(ContextFactory));
}
LogForModel(item, @"Found existing but failed re-use check.");
@ -413,7 +413,7 @@ protected virtual string ComputeHash(TModel item)
throw;
}
return item.ToLive(ContextFactory);
return Task.FromResult((ILive<TModel>?)item.ToLive(ContextFactory));
}
}
@ -480,7 +480,7 @@ private List<RealmNamedFileUsage> createFileInfos(ArchiveReader reader, RealmFil
/// <param name="archive">The archive to use as a reference for population. May be null.</param>
/// <param name="realm">The current realm context.</param>
/// <param name="cancellationToken">An optional cancellation token.</param>
protected abstract Task Populate(TModel model, ArchiveReader? archive, Realm realm, CancellationToken cancellationToken = default);
protected abstract void Populate(TModel model, ArchiveReader? archive, Realm realm, CancellationToken cancellationToken = default);
/// <summary>
/// Perform any final actions before the import to database executes.