Assign missing UserID to RealmUser

This commit is contained in:
Andrew Hong 2022-07-07 23:16:06 -04:00 committed by Andrew Hong (홍준원)
parent 315a73fb1b
commit 10d6027c89
3 changed files with 31 additions and 4 deletions

View File

@ -272,7 +272,7 @@ private void load(ReadableKeyCombinationProvider keyCombinationProvider)
dependencies.Cache(difficultyCache = new BeatmapDifficultyCache());
// ordering is important here to ensure foreign keys rules are not broken in ModelStore.Cleanup()
dependencies.Cache(ScoreManager = new ScoreManager(RulesetStore, () => BeatmapManager, Storage, realm, Scheduler, difficultyCache, LocalConfig));
dependencies.Cache(ScoreManager = new ScoreManager(RulesetStore, () => BeatmapManager, Storage, realm, Scheduler, API, difficultyCache, LocalConfig));
dependencies.Cache(BeatmapManager = new BeatmapManager(Storage, realm, RulesetStore, API, Audio, Resources, Host, defaultBeatmap, difficultyCache, performOnlineLookups: true));

View File

@ -8,11 +8,15 @@
using Newtonsoft.Json;
using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Game.Models;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.IO.Archives;
using osu.Game.Rulesets;
using osu.Game.Scoring.Legacy;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using Realms;
namespace osu.Game.Scoring
@ -26,11 +30,14 @@ public class ScoreImporter : RealmArchiveModelImporter<ScoreInfo>
private readonly RulesetStore rulesets;
private readonly Func<BeatmapManager> beatmaps;
public ScoreImporter(RulesetStore rulesets, Func<BeatmapManager> beatmaps, Storage storage, RealmAccess realm)
private readonly IAPIProvider api;
public ScoreImporter(RulesetStore rulesets, Func<BeatmapManager> beatmaps, Storage storage, RealmAccess realm, IAPIProvider api)
: base(storage, realm)
{
this.rulesets = rulesets;
this.beatmaps = beatmaps;
this.api = api;
}
protected override ScoreInfo? CreateModel(ArchiveReader archive)
@ -68,5 +75,24 @@ protected override void Populate(ScoreInfo model, ArchiveReader? archive, Realm
if (string.IsNullOrEmpty(model.StatisticsJson))
model.StatisticsJson = JsonConvert.SerializeObject(model.Statistics);
}
protected override void PostImport(ScoreInfo model, Realm realm)
{
base.PostImport(model, realm);
var userRequest = new GetUserRequest(model.User.Username);
api.Perform(userRequest);
APIUser userReq = userRequest.Response;
if (!(userReq is null)) {
Logger.Log($"Assignning UserID to RealmUser");
var user = new RealmUser
{
OnlineID = userReq.Id,
Username = model.User.Username
};
model.RealmUser = user;
}
}
}
}

View File

@ -21,6 +21,7 @@
using osu.Game.Overlays.Notifications;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Scoring;
using osu.Game.Online.API;
namespace osu.Game.Scoring
{
@ -31,7 +32,7 @@ public class ScoreManager : ModelManager<ScoreInfo>, IModelImporter<ScoreInfo>
private readonly OsuConfigManager configManager;
private readonly ScoreImporter scoreImporter;
public ScoreManager(RulesetStore rulesets, Func<BeatmapManager> beatmaps, Storage storage, RealmAccess realm, Scheduler scheduler,
public ScoreManager(RulesetStore rulesets, Func<BeatmapManager> beatmaps, Storage storage, RealmAccess realm, Scheduler scheduler, IAPIProvider api,
BeatmapDifficultyCache difficultyCache = null, OsuConfigManager configManager = null)
: base(storage, realm)
{
@ -39,7 +40,7 @@ public ScoreManager(RulesetStore rulesets, Func<BeatmapManager> beatmaps, Storag
this.difficultyCache = difficultyCache;
this.configManager = configManager;
scoreImporter = new ScoreImporter(rulesets, beatmaps, storage, realm)
scoreImporter = new ScoreImporter(rulesets, beatmaps, storage, realm, api)
{
PostNotification = obj => PostNotification?.Invoke(obj)
};