Make `Populate` abstract to avoid unnecessary base call async complexity

This commit is contained in:
Dean Herbert 2021-06-27 13:06:20 +09:00
parent f6919b70c9
commit d1f852d102
3 changed files with 8 additions and 4 deletions

View File

@ -727,7 +727,7 @@ public Task ImportFromStableAsync(StableStorage stableStorage)
/// <param name="model">The model to populate.</param>
/// <param name="archive">The archive to use as a reference for population. May be null.</param>
/// <param name="cancellationToken">An optional cancellation token.</param>
protected virtual Task Populate(TModel model, [CanBeNull] ArchiveReader archive, CancellationToken cancellationToken = default) => Task.CompletedTask;
protected abstract Task Populate(TModel model, [CanBeNull] ArchiveReader archive, CancellationToken cancellationToken = default);
/// <summary>
/// Perform any final actions before the import to database executes.

View File

@ -7,6 +7,7 @@
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
using osu.Framework.Bindables;
@ -72,6 +73,9 @@ protected override ScoreInfo CreateModel(ArchiveReader archive)
}
}
protected override Task Populate(ScoreInfo model, ArchiveReader archive, CancellationToken cancellationToken = default)
=> Task.CompletedTask;
protected override void ExportModelTo(ScoreInfo model, Stream outputStream)
{
var file = model.Files.SingleOrDefault();

View File

@ -142,16 +142,16 @@ protected override string ComputeHash(SkinInfo item, ArchiveReader reader = null
return base.ComputeHash(item, reader);
}
protected override async Task Populate(SkinInfo model, ArchiveReader archive, CancellationToken cancellationToken = default)
protected override Task Populate(SkinInfo model, ArchiveReader archive, CancellationToken cancellationToken = default)
{
await base.Populate(model, archive, cancellationToken).ConfigureAwait(false);
var instance = GetSkin(model);
model.InstantiationInfo ??= instance.GetType().GetInvariantInstantiationInfo();
if (model.Name?.Contains(".osk", StringComparison.OrdinalIgnoreCase) == true)
populateMetadata(model, instance);
return Task.CompletedTask;
}
private void populateMetadata(SkinInfo item, Skin instance)